mercredi 11 décembre 2019

Python Nested If Then statement not seen in while loop

I am developing a menu application (CLI) and when user selects a number choice from the menu then the app does something different for each choice. But first I want to make sure they enter a valid number then do something. If not a valid number, then loop through menu. If number 9 is selected, exit the application. The problem is it doesn't seem to recognize my nested if then condition statements. It just sees the first if then condition and then loops through menu again without "doing something". How do I get it to recognize the nested if thens?

import datetime
import os
import pyfiglet

def main():
    Banner()
    menu()


def menu():
    choice =int('0')
    while choice !=int('9'):
        print("1. Show the banner again")
        print("2. View just a selected date range")
        print("3. Select a date range and show highest temperature")
        print("4. Select a date range and show lowest temperature")
        print("5. Select a data range and show the highest rainfall")
        print("6. Make a silly noise")
        print("7. See this menu again")
        print("9. QUIT the program")

        choice = input ("Please make a choice: ")

        if choice.isdigit():
          print(int(choice))
          if choice == 1:
            result = pyfiglet.figlet_format("P y t h o n  R o c k s", font = "3-d" )
            print(result)
          elif choice == 2:
            getWeather()
            choice == 0
          elif choice == 3:
            print("Do Something 3")
          elif choice == 4:
            print("Do Something 4")
          elif choice == 5:
            print("Do Something 5")
          elif choice == 6:
            os.system( "say burp burp burp burpeeeeee. I love love love this menu application")
          elif choice == 7:
            print("Do Something 7")
          elif choice == 8:
            print("Do Something 8")
          elif choice == 9:
            print("***********************************************************************")
            print("Goodbye! Program exiting.....")
            print("***********************************************************************")
            exit()
        else:
          print("Your choice is not an integer. Please try again")
          print("")
          continue

def Banner():
  result = pyfiglet.figlet_format("P y t h o n  R o c k s", font = "3-d" )
  print(result)

def getWeather():
  weatherdata1 = print(input("What date would you like to start your weather data query with? Please    enter the date in this format YYYYMMDD"))
  weatherdata2 = print(input("What date would you like to end your weather data query with? Please enter the date in this format YYYYMMDD"))
  print(weatherdata1)
  print(weatherdata2)


main()

Aucun commentaire:

Enregistrer un commentaire