Python Forum

Full Version: Multi set string inputs/outputs
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I actually have no idea what to even call this as I am brand new to python
I am trying to create a simple program that generates a number of different string outputs depending on what inputs the user enters.
For example: if they input the month the program would output a message depending on what month they entered (i.e. if they input December or January or February output would be: Northern Hemisphere Winter; input other months = different seasons... you get the point.
I couldn't figure out what to look up to find this out. Making if then else statements seemed burdensome as opposed to using some sort of list definition or something.
Can I take a string input and convert a list of them into another set value ex: December, January, February, =winter?

Thank you
Do you want to print all the information for each of the inputs, or just some of them?

You could have a list of random information and print one or two. Or you could characterize them like "season_info" and "average_temp" and pick what information is returned or printed.

I'd probably prefer to store everything in a separate file with some structure and read it in. For now, maybe lets just put it in JSON format.

   "Northern Hemisphere Winter",
   "Average high temp is 46F",
   "Named for the Roman god Janus"
import json

INFOFILE = "month.json"

f = open(INFOFILE, "r")
monthdata = json.load(f)

query = input("What's your input? ")
if monthdata.get(query):
    for info in monthdata[query]:
    print(f"I have no information on {query}")
What's your input? January Northern Hemisphere Winter Average high temp is 46F Named for the Roman god Janus
What's your input? February I have no information on February
I don't need a list of information, just a message specific to if they enter a certain input, or different messages if they enter different inputs. I will look up what JSON is and how to do that though.