+ 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.

14th Nov 2019, 2:07 PM
Alec Guyer
Alec Guyer - avatar
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")
14th Nov 2019, 2:30 PM
Ipang
+ 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
14th Nov 2019, 2:29 PM
Gordon
Gordon - avatar
+ 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
14th Nov 2019, 2:33 PM
LunarCoffee
LunarCoffee - avatar
+ 1
Hello
14th Nov 2019, 5:32 PM
ahmed gaber