How to optionally repeat a program in python

前端 未结 3 1614
滥情空心
滥情空心 2020-12-12 06:23

I\'m learning python and had a quick question.

I have to write a code to find the cube root, which I\'ve done. I want to give the user the option of calculating an

3条回答
  •  再見小時候
    2020-12-12 07:05

    As an alternative to the function route, you could do it in a while loop, though it would be cleaner to use functions. You could do:

    choice = 'y'
    while choice.lower() == 'y':
        #code for the game
        choice = raw_input ('run again? (y/n)')
    

提交回复
热议问题