#Write a short program that will do the following
#Set a value your favorite number between 0 and 100
#Ask the user to guess your favorite number between 0 and 100
#Repeat until they guess that number and tell them how many tries it took
#If the value they guessed is not between 0 and 100
#tell the user invalid guess and do not count that as an attempt
내 문제는 사용자가 0에서 100 사이의 숫자를 추측하더라도 "잘못된 추측. 다시 시도하십시오"라는 내용을 계속 인쇄합니다. 허용되는 입력 (1-100)이면 반복문을 제어하여 print 문을 건너 뛰고 반복 질문을합니까? 미리 감사드립니다!Python에서 입력이 유효한 경우 조건부 if 루프가 실행되지 않도록하려면 어떻게해야합니까?
favoriteNumber = 7
attempts = 0
guess = raw_input("Guess a number between 0 and 100: ")
if (guess < 0) or (guess > 100):
print "Invalid guess. Try again"
guess = raw_input("Guess a number between 0 and 100: ")
attempts1 = str(attempts)
print "it took " + attempts1 + "attempts."
무엇 루프를 반환 raw_input을? 코드에는 아무 곳이나 반복 할 필요가 없습니다. 루프가 아닌 경우 – kindall
입니다. –