Search code examples
pythonuser-input

How to link input from user to a variable with assigned value?


I am very new to Python (literally just started learning last week). My group got an assignment to code a program to compute system that calculate total price with several conditions. But we are stuck because the user input returns as string but we need it to link with the variable. And also we aren't allowed to use IF, ELSE method and everyone is new to this so we are at dead end. Please help :')

This is what we have coded in the last hour.

min_price=30
oak_type=15
pine_type=0
black=0
white=0
gold_leaf=15
print("Welcome to Mark Daniels Carpenting Service!")
import random
order_num=random.randint(1000,1999)
print("\nYour order number is", (order_num))
cust_name=input("Enter name:")
print("Type of wood available:")
print("1 oak_type \n2 pine_type")
wood_type=input("Enter choice of wood:")

And when we tried to total up the price it comes up as error because the wood_type returns as string while the other data returns as integer.

How to make input from wood_type link to oak_type or pine_type value? wood_type=input("Enter choice of wood:")


Solution

  • You can use wood_type=int(input("Enter choice of wood:"))