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 9 6,409 Jul-21-2021, 02:53 PM
Last Post: treed226
  Input function Fabio87 10 1,600 Jan-09-2021, 11:36 AM
Last Post: gruntfutuk
  [split] How to calculate tax with a variable input and if else rokemas 1 697 Dec-28-2020, 06:53 AM
Last Post: buran
  Print user input into triangle djtjhokie 1 804 Nov-07-2020, 07:01 PM
Last Post: buran
  Python variable and function usage at a time prasanthbab1234 14 2,029 Sep-24-2020, 01:48 PM
Last Post: prasanthbab1234
  Changing Directory based on user input paulmerton4pope 13 2,023 Aug-14-2020, 11:48 AM
Last Post: GOTO10
  how to add the user input from file into list wilson20 8 2,003 May-03-2020, 10:52 PM
Last Post: Larz60+
  coding a function helpless_coder 7 1,121 Apr-30-2020, 03:31 AM
Last Post: deanhystad
  How to make the function to prompt the user repeatedly till he enters a no sbabu 3 1,151 Mar-26-2020, 10:04 PM
Last Post: Blackdog31
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 2,113 Feb-27-2020, 09:22 AM
Last Post: buran

Forum Jump:

User Panel Messages

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