鱼C论坛

 找回密码
 立即注册
查看: 339|回复: 2

请问这组代码出什么问题了? 我改了好久都改不出来

[复制链接]
发表于 2018-12-14 18:58:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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')


谢谢大家的帮助!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-12-14 19:06:01 | 显示全部楼层
str(temp) == "AND" or 'And' or 'and' 不能简写把每个等式都写出来,其他类似
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-12-15 23:47:49 | 显示全部楼层
好的,我去改,谢谢指导!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-30 17:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表