Python Forum

Full Version: New to Python - tiny coding assistance on user input function and assign to variable
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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