-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonMinigames.py
More file actions
132 lines (112 loc) · 3.76 KB
/
PythonMinigames.py
File metadata and controls
132 lines (112 loc) · 3.76 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
################################
# Author: Rahim Siddiq
# Python Minigames
################################
###Problem 1###
import random
while True:
flip = random.randint(1, 2)
choice = int(input("Enter the number 1 For Heads, 2 For Tails or 0 To Exit"))
if choice == 0:
print("Goodbye")
break
elif choice == flip:
print("You win")
else:
print("You loose")
###Problem 2###
import random
randomn = random.randint(1, 10)
guess = int(input("Guess any number 1 to 10?"))
count = 1
while True:
if guess < randomn:
print("You guessed too low")
elif guess > randomn:
print("You guessed too high")
else:
print("You guessed correctly, it only took you", count, "tries")
break
count = count + 1
guess = int(input("Guess any number 1 to 10?"))
###Problem 3###
import random
def read_choice():
print("Select operation.")
return int(input("Enter the number of the operation 1. Add // 2. Subtract // 3. Multiply // 4. Divide // 5. Guessing game coinflip // 6. Guessing game random // 7. Exit):"))
def guessing_game_coinflip():
while True:
flip = random.randint(1, 2)
choice = int(input("Enter the number 1 For Heads, 2 For Tails or 0 To Exit"))
if choice == 0:
print("Goodbye")
break
elif choice == flip:
print("You win")
else:
print("You loose")
def guessing_game_random():
import random
randomn = random.randint(1, 10)
guess = int(input("Guess any number 1 to 10?"))
count = 1
while True:
if guess < randomn:
print("You guessed too low")
elif guess > randomn:
print("You guessed too high")
else:
print("You guessed correctly, it only took you", count, "tries")
break
count = count + 1
guess = int(input("Guess any number 1 to 10?"))
def add_numbers(n1, n2):
print("{} + {} = {}".format(n1, n2, n1 + n2))
def subtract_numbers(n1, n2):
print("{} - {} = {}".format(n1, n2, n1 - n2))
def multiply_numbers(n1, n2):
print("{} * {} = {}".format(n1, n2, n1 * n2))
def divide_numbers(n1, n2):
if n2 == 0:
print("Cannot divide by zero")
else:
print("{} / {} = {}".format(n1, n2, n1 / n2))
def main():
while True:
choice = read_choice()
if 1 <= choice <= 4:
n1 = int(input("Enter first number: "))
n2 = int(input("Enter second number: "))
if choice == 1:
add_numbers(n1, n2)
elif choice == 2:
subtract_numbers(n1, n2)
elif choice == 3:
multiply_numbers(n1, n2)
elif choice == 4:
divide_numbers(n1, n2)
elif choice == 5:
guessing_game_coinflip()
elif choice == 6:
guessing_game_random()
elif choice == 7:
print("Goodbye")
break
else:
print("Invalid choice!")
main()
###Problem 4###
print("Please enter you age in whole years, remainder days, and remainder hours to see the total seconds you've lived")
years = int(input("Enter the number of years since your birth"))
days = int(input("Enter the remainder of days"))
hours = int(input("Enter the remainder of hours"))
leap = input("Would you like to factor in leap years? y/n")
if leap == "y":
leap_days = years // 4 - years // 100 + years // 400
secondsleap = (years * 31536000 + leap_days * 86400 + days * 86400 + hours * 3600)
print("Seconds you have lived thus far:", secondsleap)
elif leap == "n":
seconds = (years * 31536000 + days * 86400 + hours * 3600)
print("Seconds you have lived thus far:", seconds)
else:
print("Enter y/n for: Would you like to factor in leap years?")