-
Notifications
You must be signed in to change notification settings - Fork 10
/
Christina's BC Codes
95 lines (69 loc) · 1.93 KB
/
Christina's BC Codes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Exercise 1: Print the Time
currenttime <- Sys.time()
print(currenttime)
# Exercise 2: Make a Simple Stopwatch
starttime <- Sys.time()
print(currenttime)
greeting <- "hello world"
print(greeting)
endtime <- Sys.time()
print(endtime - starttime)
# Exercise 3: Print a Word Provided by the User
# get input from user
my.word <- readline(prompt="Enter your word: ")
print(paste("Your word is ", my.word))
# Exercise 4: Validate User Input
my.word <- readline(prompt="Enter your word: ")
if(class(my.word)!= "character") {
my.word <- readline(prompt="This is not a word. Enter another: ")
print(paste("Your word is ", my.word))
} else {
print("This is a word")
}
# Exercise 5: Record and Print a List
GetMultipleNumbers <- function()
{
i <- 0
mylist = vector()
while(i<5) {
num <- readline(prompt="Input one integer: ")
mylist = c(mylist,num)
i <- i+1
}
# Loop over list and print
for (i in mylist) {
print(i)
}
}
GetMultipleNumbers()
#--------------------------------------------
#Python Exercises
Created on Fri Jan 3 21:19:54 2020
@author: Christina
"""
# Exercise 1: Print the Time
import datetime
print(datetime.datetime.now())
# Exercise 2: Make a Simple Stopwatch
starttime = datetime.datetime.now()
greeting = "hello world"
print(greeting)
endtime = datetime.datetime.now()
print(endtime - starttime)
# Exercise 3: Print a Word Provided by the User
# prompt user for a word
userword = input("Please enter a word: ")
print(userword)
# Exericse 4: Validate User Input
userword=str(input("Please enter a word: "))
if not userword.isalpha():
print("Your word must consist of letters only")
userword=str(input("Please enter a word: "))
print("Your word is " + userword)
else:
print("Your word is " + userword)
# Exercise: Record and Print a List
input_string = input("Enter a list numbers or elements separated by space: ")
userList = input_string.split()
for int in userList:
print(int)