-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_structures_exercises
52 lines (39 loc) · 1.78 KB
/
control_structures_exercises
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
# This is the exercises for the control structures.
#1 Conditinal basics
#a prompt the user for a day of the week, print out whether the day is Monday or not
day = input('Please enter day of the week:'):
print('Today is, ' + x);
#b prompt the user for a day of the week, print out whether the day is a weekday or a weekend
#c create variables and make up values for and write the python code that calculates the weekly paycheck. You get paid time and a half if you work more than 40 hours
# the number of hours worked in one week
# the hourly rate
# how much the week's paycheck will be
#2 Loop Basics
#A While
# Create an integer variable i with a value of 5.
# Create a while loop that runs so long as i is less than or equal to 15
# Each loop iteration, output the current value of i, then increment i by one.
i = 5
while i <= 15:
print(i)
i +=1;
#Create a while loop that will count by 2's starting with 0 and ending at 100. Follow each number with a new line.
i = 0
while i <= 100:
print(i)
i += 2;
# Alter your loop to count backwards by 5's from 100 to -10.
i = 100
while i >= -10:
print(i)
i -= 5;
# Create a while loop that starts at 2, and displays the number squared on each line while the number is less than 1,000,000. Output should equal:
i = 2
while i < 100000:
print(i**2)
i *=i;
# Write a loop that uses print to create the output shown below.
#B For Loops
#Write some code that prompts the user for a number, then shows a multiplication table up through 10 for that number.
for i in the range(1,10):
print (i)