-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial5.py
More file actions
105 lines (75 loc) · 3.11 KB
/
Copy pathTutorial5.py
File metadata and controls
105 lines (75 loc) · 3.11 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
#Tutorial 5
#Question 1
#decision = input("Enter N or n if you do not wish to continue to play the game:")
#while decision != 'N' or decision != 'n':
#import random
#secret_num = random.randint(1, 200)
#guess_num = int(input("Guess my secret number: "))
#count = 1
#while guess_num != secret_num:
#if guess_num < secret_num:
#print("Too Low")
#elif guess_num > secret_num:
#print("Too High")
#count += 1
#guess_num = int(input("Have another guess:"))
#print(f"Well done, you took {count} attempts")
#decision = input("Enter N or n if you do not wish to continue:")
#print("Thank you for playing the game.")
#Question 2
a = int(input("Which multiplication table would you like to print?"))
b = int(input("How high would you like it to go?"))
count = 1
print("Here is your multiplication table:")
while count <= b:
result = a * b
print(f"{a} times {b} = {result}")
b -= 1
count += 1
#Question 3
#Use list to list down the index of elements
bits = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
count = 1
while count <= 5:
#retrieving element from the list
print(bits[0], bits[1], bits[2], bits[3], bits[4],bits[5], bits[6], bits[7], bits[8], bits[9], bits[10], sep = "")
count +=1
#Question 4
print(f"[1] Convert Celsius to Fahrenheit")
print(f"[2] Convert Fahrenheit to Celsius")
while True:
try:
Selection = int(input("Enter your selection, 1 or 2:"))
except:
print("ERROR: Invalid Selection!")
Selection = print("Please enter 1 to convert Celsius to Fahrenheit or 2 to Convert Fahrenheit to Celsius")
else:
while Selection == 1:
print(f"Celsius (C) to Fahrenheit (F) Conversion")
print(f"Enter temperature in integer values only.")
min_temp = int(input("Enter minimum temperature:"))
max_temp = int(input("Enter maximum temperature:"))
Celsius = min_temp
while min_temp <= max_temp:
Fahrenheit = (Celsius * 9/5) + 32
print(f"{min_temp}C = {Fahrenheit}F")
min_temp +=1
print("Conversion Done!")
decision = input("Do you want to run the program again? [Y/N:]")
if decision == "N":
break
while True:
while Selection == 2:
print(f"Fahrenheit (F) to Celsius (C) Conversion")
print(f"Enter temperature in integer values only.")
min_temp = int(input("Enter minimum temperature:"))
max_temp = int(input("Enter maximum temperature:"))
Fahrenheit = min_temp
while min_temp <= max_temp:
Celsius = (Fahrenheit - 32) * 5/9
print(f"{min_temp}C = {Fahrenheit}F")
min_temp +=1
print("Conversion Done!")
decision = input("Do you want to run the program again? [Y/N:]")
if decision == "N":
break