+ 1
How do you prompt a user to restart the code and how do you use the prompt to restart the code?
I'm trying to make a payroll code ask at the end if they want to do it again but I cant figure out how to use the input to restart the code.
5 ответов
+ 6
Use a `while` loop and read user confirmation within the loop body.
while True:
# code to process your data here
confirm = input("Input more data? ")
print(confirm) # for Code Playground
if confirm.lower() == "y":
continue # repeat loop
break # exit loop
print("See you later")
+ 3
Declare variables in global scope.
Initialize the variables in a function called init()
Call the function init() at window.onload
Call the function init() when restart condition is met (for example restart button is clicked)
https://code.sololearn.com/WrZat1vLX669/?ref=app
+ 3
You can use a loop which runs a function which does all the work, and asks at the end if they want to continue. If they don't, you can exit the loop. If they do, you can continue the loop. Something like:
while True:
payroll()
if input("Exit?").casefold() == "y":
break
+ 1
Hello