I read the guidelines on posting homework questions and I think this one is within the rules. A little background, currently taking my first computer program class, its an online class (big mistake), it's very hard to get feedback or assistance.
I have been ripping my hair out trying to figure out this program. I already completed the flowchart and the instructor said it was correct. Now I'm trying to write the program from the flowchart and have hit a few bumps.
First off, in my while loop its supposed to validate either a 1 , 2 , 3 was entered. The instructor wants the Boolean to be != 1 and !=2 and !=3. After reading the text 20 times I still don't understand why not 1 and not 2 and not 3 is the proper way to do this. He even sent an email saying he was getting alot of questions and this is usually the hardest part of the program.
I have been tinkering with the loop for the better part of 4 hours and have officially run out of ideas.
I'm sure there are additional problems I will encounter later on, but is there any way someone could offer a hint to walk me through this?
Heres the code....Thanks
import random
#define the main function
def main():
play_again ='y'
com_choice()
play_choice()
deter_winner(com_choice,play_choice)
while play_again == 'y' or play_again =='Y':
com_choice()
play_choice()
print 'The computer selects', com_choice, 'for its throw',
deter_winner(com_choice, play_choice)
play_again = raw_input ('Play again?')
#computer choice is randomly generated
def com_choice():
cchoice=random.randrange(1,4)
return com_choice
def play_choice():
play_choice = raw_input
while play_choice != 1 and play_choice != 2 and play_choice != 3:
print 'Invalid choice'
play_choice = (input('Enter a valid choice:'))
#determine the winner
def deter_winner(play_choice,com_choice):
if com_choice == 1 and play_choice == 2:
print 'Paper covers rock, you win.'
elif com_choice == 2 and play_choice == 3:
print 'Scissors cuts paper, you win.'
elif com_choice == 3 and play_choice == 1:
print 'Rock smashes scissors, you win.'
elif com_choice == 1 and play_choice == 3:
print 'Rock smashes scissors, you lose'
elif com_choice == 2 and play_choice == 1:
print 'Paper covers rock, you lose'
elif com_choice == 3 and play_choice == 2:
print 'Scissors cuts paper, you lose'
elif com_choice ==1 and play_choice == 1:
print ',its a draw'
elif com_choice == 2 and play_choice == 2:
print ',its a draw'
elif com_choice == 3 and play_choice == 3:
print ',its a draw'
else:
print''
main()