-1

So I have the following test script I am playing with.

import time

year = time.strftime('%Y')
name = input('What is your name? ')
dob = input('What is your DOB ')
age = int(year) - int(dob)

print(f'{name}, You are {age} years old.')

How do I start this script over after it prints out the last statement? Sorry for such a silly question, I have been looking everywhere but cannot find anything. Thanks in advance.

KevinM1990112qwq
  • 715
  • 2
  • 10
  • 23

2 Answers2

3

If you know how many times you want to run this code, use for loops ; if it mainly depends on a condition, use while loop. To run your code forever, do while True:.

ted
  • 13,596
  • 9
  • 65
  • 107
0

I would use a for statement, this will also allow you to specify the number of times you would like to run this.

import time
n = 2

for _ in range(n):
    year = time.strftime('%Y')
    name = input('What is your name? ')
    dob = input('What is your DOB ')
    age = int(year) - int(dob)

    print(f'{name}, You are {age} years old.')

If you would like to run forever then use while loops.

import time

while True:
    year = time.strftime('%Y')
    name = input('What is your name? ')
    dob = input('What is your DOB ')
    age = int(year) - int(dob)

    print(f'{name}, You are {age} years old.')