Python Forum
New to Python - tiny coding assistance on user input function and assign to variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Python - tiny coding assistance on user input function and assign to variable
#1
Hi all,

I am new to Python and was wondering if anyone can simply help me with the following. I am tasked with created a basic drink ordering program and am stuck on the following:

Getting size: Create a function called "get_size" that asks the user what size beverage the user wants (S,M,L) and assigns it to a variable called "size_input". If the user enters an invalid value, , assume the size is a Small. Based on their input, return a variable called “size” from the function.


I am stuck on the second and third part - how do I create a variable from the users input? is it simply size_input = get_size?
Furthermore, how do I create a "size" variable from an existing variable? It seems redundant.

Apologies in advance if I am not wording/asking this correctly, this is a whole new world for me.

THanks!

MD
Reply
#2
size_input would be the result of user input
size_input = input('what size beverage (S,M,L)')
you are required to then check that the value of size_input is one of (S,M,L), if it is simply just
size = size_input
otherwise
size = 'S'
and then
return size
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to calculate tax with a variable input and if else afefDXCTN 12 22,787 Mar-15-2024, 01:58 AM
Last Post: nave
Question Need help with NumPy Histogram function coding Triikey 1 922 May-15-2023, 01:45 PM
Last Post: deanhystad
  How to create a menu and execute a function based on user selection in python? Thedarkphoenix 1 1,317 Nov-23-2022, 07:53 PM
Last Post: Larz60+
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,281 Nov-12-2022, 03:47 AM
Last Post: deanhystad
  Input function Fabio87 11 5,939 Apr-29-2022, 03:50 PM
Last Post: Alex143
  [split] How to calculate tax with a variable input and if else rokemas 1 2,110 Dec-28-2020, 06:53 AM
Last Post: buran
  Print user input into triangle djtjhokie 1 2,368 Nov-07-2020, 07:01 PM
Last Post: buran
  Python variable and function usage at a time prasanthbab1234 14 5,105 Sep-24-2020, 01:48 PM
Last Post: prasanthbab1234
  Changing Directory based on user input paulmerton4pope 13 7,986 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  how to add the user input from file into list wilson20 8 4,312 May-03-2020, 10:52 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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