是否有退出功能的命令?
我才刚开始学蟒蛇。我试着写了一个猜测数字的小代码。我想知道我们是否可以只退出功能,而不是整个程序。
选择 | 换行 | 行号
- def user_guess(num):
- if(num==rand_num):
- print "hurrey! you guessed it right.\n"
- another_try=raw_input("would you like to guess another number??\n")
- if(another_try == "y" or another_try == "yes"):
- num = int(input("Guess the number!\n"))
- return num
- else:
- print "okay! have a good day!"
- sys.exit()
- elif(num>rand_num):
- print "your guessed number is greater than the actual number,,\n"
- guess_again=raw_input("would you like to guess the same number again??\n")
- if(guess_again == "y" or guess_again == "yes"):
- num=int(input("guess the number"))
- user_guess(num)
- else: #here i want to get out of the function only,I want the other part of the program to run
- elif(num<rand_num):
- print "your guessed number is lesser than the actual number,,\n"
- else:
有谁能帮帮我吗?(如果有其他错误,请不要理会)