|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
第一次不管输入什么,都会变成OR门的处理
改到后面我从写了一份,可还是一样的问题
这是代码
temp2 = input('Press \'Enter\' to start, you can press \'q\' to stop.')
while temp2 != 'q':
temp = input('Please enter your logic gate: ')
if str(temp) == 'OR' or 'Or' or 'or':
first = input('Please enter your first input: ')
second = input('Please enter your second input: ')
if first and second == 0:
print ('Result is 0.')
else:
print ('Result is 1.')
else:
if str(temp) == "AND" or 'And' or 'and':
first = input('Please enter your first input: ')
second = input('Please enter your second input: ')
if first and second == 1:
print ('Result is 1.')
else:
print ('Result is 0.')
else:
if str(temp) == 'XOR' or 'Xor' or 'xor':
first = input('Please enter your first input: ')
second = input('Please enter your second input: ')
if first and second == 0 or 1:
print ('Result is 0.')
else:
print ('Result is 1.')
else:
print ('Sorry, we don\'t do this.')
temp2 = input('Press \'Enter\' to start again, you can press \'q\' to stop.')
这是第二份
start = input('Press "Enter" to start, you can press "q" to stop.')
while start != 'q':
Input = input('Please enter your logic gate: ')
if Input != 'OR' or 'Or' or 'or':
if Input != 'XOR' or 'Xor' or 'xor':
first = input('Please enter your first input: ')
second = input('Please enter your second input: ')
if first and second == 1:
print ('Result is 1.')
else:
print ('Result is 0.')
else:
first = input('Please enter your first input: ')
second = input('Please enter your second input: ')
if first and second == 0 or 1:
print ('Result is 0.')
else:
print ('Result is 1.')
else:
first = input('Please enter your first input: ')
second = input('Please enter your second input: ')
if first and second == 0:
print ('Result is 0.')
else:
print ('Result is 1.')
start = input('Press "Enter" to start a again, you can press "q" to stop.')
顺便放上用了一样方法的剪刀石头布:
import random
temp1 = ['Rock', 'Paper', 'Scissors']
print ('Press "q" to quit.')
temp2 = input('Press "Enter" to start.')
while temp2 != 'q':
guess = input('Enter your choice: ')
temp3 = temp1[random.randint(0, 2)]
if len(temp3) == len(guess):
print ("We\'re ", temp3, ". It's a draw.")
else:
if len(temp3) < len(guess):
if len(guess) < 9:
if len(guess) == 8:
if len(temp3) == 5:
print ('We\'re ', temp3, '. You win.')
else:
print ('We\'re', temp3, '. You lose!')
else:
print ("We\'re ", temp3, '. You win!')
else:
print ('Did you just type someting strange?')
else:
if len(temp3) == 8:
if len(guess) == 5:
print ('We\'re ', temp3, '. You lose.')
else:
print ('We\'re ', temp3, '. You win!')
else:
print ('We\'re ', temp3, '. You lose.')
temp2 = input('Press "Enter" again to a new match')
谢谢大家的帮助! |
|