Python Forum
[Beginner] Code is not producing desired result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Beginner] Code is not producing desired result
#1
1. How to define range 1 to infinity in function range()?
2. Am I using for-else loop correctly?
3. Also even if I enter everything correctly following is the result:

Your age in 1 will be: 1

Thanks

print('\nThis is a program to detemine your age in any year.\n')
currentAge = currentYear = futureAge = futureYear = 0

currentAge = int(input('\nEnter your current age in years: '))

for currentAge in range(1,95):
    break

else:
    currentAge = int(input('\nEnter your real age (1 - 95): '))


currentYear = int(input('\nEnter current year: '))

for currentYear in range(1, 9999999):
    break

else:
    currentYear = int(input('Please enter valid year: '))


futureYear = int(input('\nEnter the year to determine your age in that year: '))

for futureYear in range(1, 9999999):
    break

else:
    futureYear = int(input('Please enter valid year: '))

futureAge = currentAge + (futureYear - currentYear)

if futureAge > 0:

    if futureAge > 95 and futureYear > currentYear:
        print('\nYour age in', futureYear, 'will be:', futureAge)
        print('\nAre you sure you are going to be alive by then!')

    elif futureYear < currentYear:
        print('\nYour age in', futureYear, 'was:', futureAge)

    else:
        print('\nYour age in', futureYear, 'will be:', futureAge)

else:
    print('\nYou weren\'t alive in', futureYear, ".")
Reply


Messages In This Thread
[Beginner] Code is not producing desired result - by fakej171 - Mar-20-2020, 02:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner: Code not work when longer list raiviscoding 2 896 May-19-2023, 11:19 AM
Last Post: deanhystad
  Json filter is not capturing desired key/element mrapple2020 1 1,201 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  help me simple code result min and max number abrahimusmaximus 2 973 Nov-12-2022, 07:52 AM
Last Post: buran
  Filter and str.isdigit producing an error tester_V 5 2,068 Aug-12-2022, 07:50 AM
Last Post: Gribouillis
  Can a program execute code in iPython shell and get result? deanhystad 3 1,806 Jun-17-2022, 03:45 AM
Last Post: Larz60+
  pyautogui.locateOnScreen producing error dude8074 6 3,998 Apr-17-2022, 05:05 PM
Last Post: bowlofred
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,576 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  how can I display only desired items? 3lnyn0 5 2,147 Dec-25-2021, 06:49 PM
Last Post: menator01
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,660 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  producing numbers out of a list bouraque7878 10 3,903 Nov-12-2021, 09:13 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020