Difference between revisions of "CSC111 Lab3 Solutions 2014"
Line 182: | Line 182: | ||
if computerScore > humanScore: | if computerScore > humanScore: | ||
− | print( "You lose | + | print( "You lose! I am sorry, but you are no match for me!" ) |
elif computerScore < humanScore: | elif computerScore < humanScore: | ||
print( "You win the 3 rounds! Congrats!" ) | print( "You win the 3 rounds! Congrats!" ) |
Revision as of 11:44, 13 February 2014
--D. Thiebaut (talk) 08:55, 12 February 2014 (EST)
Solution Programs for Lab 3
# Solutions programs for Lab 3
#
# Test case 1
x = int( input( "Please enter an integer: " ) )
if x > 10 :
print( "valid input" )
else:
print( "invalid input" )
# Test case 2
x = int( input( "Please enter an integer: " ) )
if x > 10 and x < 20 :
print( "valid input" )
else:
print( "invalid input" )
# Test case 3
x = int( input( "Please enter an integer: " ) )
if x >= 10 and x <= 20 :
print( "valid input" )
else:
print( "invalid input" )
# Test case 4
x = int( input( "Please enter an integer: " ) )
if x % 2 == 0:
print( "valid input" )
else:
print( "invalid input" )
# Test case 5
x = int( input( "Please enter an integer: " ) )
if x % 2 == 0 and x % 5 == 0:
print( "valid input" )
else:
print( "invalid input" )
# Test case 6
x = int( input( "Please enter an integer: " ) )
if x % 2 == 0 and x >=0 and x <=100:
print( "valid input" )
else:
print( "invalid input" )
#
# LARGEST OF 3
#
x = int( input( "> " ) )
y = int( input( "> " ) )
z = int( input( "> " ) )
if x <= y and x <= z:
print( x, "is the smallest" )
elif y <= x and y <= z:
print( y, "is the smallest" )
else:
print( z, "is the smallest" )
#
# SANTA
#
name = input( "Hello! What is your name? " )
name = name.lower()
if name.find( "santa" ) != -1:
print( "Ho, Ho, Ho Santa Claus!" )
else:
print( "Hello there, " + name + "!" )
#
# MOTHER/FATHER
#
answer = input( "How was your day? " ).lower()
if answer.find( "mother" )!= -1 or answer.find( "father" ) != -1:
print( "Should we talk about your family?" )
else:
print( "Glad to hear that!" )
print( "Good bye!" )
#
# ROCK/PAPER/SCISSORS
#
from random import choice
OPTIONS = ['R', 'P', 'S' ]
computer = choice( OPTIONS )
human = input( "What is your play? " ).upper()
print( "The compute has chosen", computer )
if ( computer=='R' and human=='P' ) \
or ( computer=='P' and human=='S' ) \
or ( computer=='S' and human=='R ):
print( "Congrats, you win!" )
elif ( computer=='R' and human=='S' ) \
or ( computer=='P' and human=='R' ) \
or ( computer=='S' and human=='P ):
print( "Sorry, you lose this time!" )
else:
print( "It's a tie!" )
#
# keeping scores
#
computerScore = 0
humanScore = 0
# Round 1
computer = choice( OPTIONS )
human = input( "What is your play? " ).upper()
print( "The compute has chosen", computer )
if ( computer=='R' and human=='P' ) \
or ( computer=='P' and human=='S' ) \
or ( computer=='S' and human=='R ):
print( "Congrats, you win!" )
humanScore = humanScore + 1
elif ( computer=='R' and human=='S' ) \
or ( computer=='P' and human=='R' ) \
or ( computer=='S' and human=='P ):
print( "Sorry, you lose this time!" )
computerScore = computerScore + 1
else:
print( "It's a tie!" )
# Round 2
computer = choice( OPTIONS )
human = input( "What is your play? " ).upper()
print( "The compute has chosen", computer )
if ( computer=='R' and human=='P' ) \
or ( computer=='P' and human=='S' ) \
or ( computer=='S' and human=='R ):
print( "Congrats, you win!" )
humanScore = humanScore + 1
elif ( computer=='R' and human=='S' ) \
or ( computer=='P' and human=='R' ) \
or ( computer=='S' and human=='P ):
print( "Sorry, you lose this time!" )
computerScore = computerScore + 1
else:
print( "It's a tie!" )
# Round 3
computer = choice( OPTIONS )
human = input( "What is your play? " ).upper()
print( "The compute has chosen", computer )
if ( computer=='R' and human=='P' ) \
or ( computer=='P' and human=='S' ) \
or ( computer=='S' and human=='R ):
print( "Congrats, you win!" )
humanScore = humanScore + 1
elif ( computer=='R' and human=='S' ) \
or ( computer=='P' and human=='R' ) \
or ( computer=='S' and human=='P ):
print( "Sorry, you lose this time!" )
computerScore = computerScore + 1
else:
print( "It's a tie!" )
if computerScore > humanScore:
print( "You lose! I am sorry, but you are no match for me!" )
elif computerScore < humanScore:
print( "You win the 3 rounds! Congrats!" )
else:
print( "Your 3 rounds end in a tie!" )