lesson 3 done
This commit is contained in:
commit
33451d727a
BIN
Problem Set 1.pdf
Normal file
BIN
Problem Set 1.pdf
Normal file
Binary file not shown.
25
ps1_1_joseph_green.py
Normal file
25
ps1_1_joseph_green.py
Normal file
@ -0,0 +1,25 @@
|
||||
#When will user be 100
|
||||
#What is your name?
|
||||
#How old are you?
|
||||
#Hey USER you will be 100 in YEAR
|
||||
|
||||
import time
|
||||
|
||||
user = None
|
||||
age = None
|
||||
birthday = None
|
||||
|
||||
user = input("What is your name? ")
|
||||
age = input("How old are you? ")
|
||||
birthday = input("Have you had your birthday yet this year? (y/n) ")
|
||||
|
||||
if birthday == "y" or birthday == "n":
|
||||
try:
|
||||
age = int(age)
|
||||
if birthday == "n":
|
||||
age += 1
|
||||
print("Hey ", user, "you will be 100 in the year ", 100 - age + time.gmtime().tm_year)
|
||||
except:
|
||||
print("Please use only Arabic numerals for your age!!!")
|
||||
else:
|
||||
print("Please only enter a 'y' or an 'n'")
|
19
ps1_2_joseph_green.py
Normal file
19
ps1_2_joseph_green.py
Normal file
@ -0,0 +1,19 @@
|
||||
#ask user for a number
|
||||
#report even or odd
|
||||
|
||||
number = None
|
||||
result = None
|
||||
evenOdd = None
|
||||
|
||||
try:
|
||||
number = int(input("Please enter a number: "))
|
||||
result = number % 2
|
||||
if result == 0:
|
||||
evenOdd = "even"
|
||||
else:
|
||||
evenOdd = "odd"
|
||||
|
||||
print(str(number) + ",is an " + evenOdd + " number")
|
||||
except:
|
||||
print("Only enter an integers!")
|
||||
|
53
ps1_3_joseph_green.py
Normal file
53
ps1_3_joseph_green.py
Normal file
@ -0,0 +1,53 @@
|
||||
# Two player Rock Paper Scissors game
|
||||
# Congradulate winner
|
||||
# Ask if players wish to play again
|
||||
|
||||
players = ["",""]
|
||||
quit = False
|
||||
playersQuit = "y"
|
||||
winner = "player "
|
||||
tie = None
|
||||
|
||||
while quit == False:
|
||||
i = 0
|
||||
tie = None
|
||||
winner = "player "
|
||||
|
||||
while i <=1: #Is there no for (i=0; i<2; i++) equiv in python?
|
||||
print ("\n" * 100)
|
||||
players[i] = input("Player " + str(i + 1) + ", enter (R)ock, (P)aper, or (S)cissors:" )
|
||||
players[i] = players[i].lower()
|
||||
|
||||
if players[i] == "r" or players[i] == "p" or players[i] == "s":
|
||||
i += 1
|
||||
## else, repeat question
|
||||
|
||||
|
||||
|
||||
if players[0] == players[1]:
|
||||
tie = True
|
||||
print("We have a tie!!!")
|
||||
|
||||
elif players[0] == "r" and players[1] == "p":
|
||||
winner += "2"
|
||||
elif players[0] == "r" and players[1] == "s":
|
||||
winner += "1"
|
||||
|
||||
elif players[0] == "s" and players[1] == "p":
|
||||
winner += "1"
|
||||
elif players[0] == "s" and players[1] == "r":
|
||||
winner += "2"
|
||||
|
||||
elif players[0] == "p" and players[1] == "s":
|
||||
winner += "2"
|
||||
elif players[0] == "p" and players[1] == "r":
|
||||
winner += "1"
|
||||
|
||||
if tie != True:
|
||||
print("Congrats", winner, "You've won!")
|
||||
|
||||
|
||||
playersQuit = input("Would you like to play again? (y/n): ")
|
||||
|
||||
if playersQuit.lower() == "n":
|
||||
quit = True
|
0
ps1_4_joseph_green.py
Normal file
0
ps1_4_joseph_green.py
Normal file
Loading…
x
Reference in New Issue
Block a user