这是一个程序,需要3位数字,存储它们,并反复猜测和检查,直到三个存储的数字与3个猜测的数字相匹配。我似乎无法通过第一个while循环执行任何操作:
digitone = int(raw_input())
digittwo = int(raw_input())
digitthree = int(raw_input())
digitthree = int(raw_input())
countdigitone = 0
countdigittwo = 0
countdigitthree = 0
while digitone <= countdigitone:
if digitone < countdigitone:
print "Digit one could be", countdigitone
countdigitone += 1
elif digitone == countdigitone:
print "Digit one is", countdigitone
while digittwo <= countdigittwo:
if digittwo < countdigittwo:
print "The first two digits could be", countdigitone, countdigittwo
countdigittwo += 1
elif digittwo == countdigittwo:
print "Digits one and two are", countdigitone, countdigittwo
while digitthree <= countdigitthree:
if digitthree < countdigitthree:
print "The 3-digit number could be", countdigitone, countdigittwo, countdigitthree
countdigitthree += 1
elif digitthree == countdigitthree:
print "This is most definetly the number!", countdigitone, countdigittwo, countdigitthree
break
就是这样。目前,它只需要你的数字,打印单词none,然后停止。有什么方法可以解决这个问题吗?
答案 0 :(得分:0)
while digitone <= countdigitone
表示除非digitone是负数,否则它将永远不会小于设置为0的countdigitone
我会执行以下操作,循环直到找到每个数字的值并在结尾处打印值:
digit_one = int(raw_input())
digit_two = int(raw_input())
digit_three= int(raw_input())
count_digit_one = 0
count_digit_two = 0
count_digit_three= 0
while digit_one > count_digit_one:
print "Digit one could be", count_digit_one
count_digit_one += 1
while digit_two > count_digit_two:
print "The first two digits could be", count_digit_one, count_digit_two
count_digit_two += 1
while digit_three> count_digit_three:
print "The first three digits could be", count_digit_one, count_digit_two
count_digit_three += 1
print "This is most definitely the number! {}{}{}".format(count_digit_one, count_digit_two, count_digit_three)
答案 1 :(得分:0)
第一个while循环正在执行
while digitone <= countdigitone:
您已从用户那里获得digitone
。并且您已将countdigitone
设置为0.除非他们输入的数字小于0,否则您根本不会进入while
循环。