Python Forum
Multi set string inputs/outputs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi set string inputs/outputs
#1
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
Kevin
Reply
#2
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.

month.json
{"January":[
   "Northern Hemisphere Winter",
   "Average high temp is 46F",
   "Named for the Roman god Janus"
   ]
}
code
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(info)
else:
    print(f"I have no information on {query}")
Output:
What's your input? January Northern Hemisphere Winter Average high temp is 46F Named for the Roman god Janus
Output:
What's your input? February I have no information on February
Reply
#3
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.
Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use subprocess to get multiple data outputs in desired folder? 3SG14 1 326 Sep-19-2020, 05:46 PM
Last Post: bowlofred
  How to write a response if a user inputs a string horuscope42 3 547 Apr-29-2020, 03:39 PM
Last Post: deanhystad
  Outputs missing SamAnw 4 464 Feb-12-2020, 04:32 PM
Last Post: adetheheat
  Problem with accepting multiple string inputs Ryan_Todd 5 563 Jan-22-2020, 06:12 PM
Last Post: buran
  Python convert multi line into single line formatted string karthidec 2 1,702 Dec-23-2019, 12:46 PM
Last Post: karthidec
  Interpreter and running a .py file give different outputs PythonNPC 5 750 Jul-21-2019, 01:07 PM
Last Post: PythonNPC
  Save outputs to Desktop cisicomania 1 967 Aug-31-2018, 10:08 AM
Last Post: Gribouillis
  Help Editing/Problem with outputs stanthaman42 7 1,550 Jul-11-2018, 05:30 PM
Last Post: ichabod801
  how do i rewrite this code to give me 10 outputs BlackPimpernel 2 1,046 Mar-29-2018, 11:29 AM
Last Post: BlackPimpernel
  Different outputs in Python2 and Python3 MikeHill 3 2,026 Jun-07-2017, 08:58 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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