The input( ) function accepts everything as a STRING. Look below:
my_number = input("Pick a Number")
print(my_number)
#Sample:
#If You Put in 21, it prints 21... but it's not the
# number 21. It's a STRING containing 21!!! Strange??
This looks like you're putting in a number. HOWEVER, you're really putting in a STRING!!!
This isn't a problem if all you want to do is print a value. But, if you wanna work with it, it's a completely different story:
#Have the user enter their age
star_num = input("How Many Stars To Print?? ")
#Print the number of stars using string multiplication
print(star_num * "*")
What happened when you tried to run this?
Does this code run?
Why not?
Can we do string * string?? Is that something in Python??
CHALLENGE:
Make this run. Fix it and tell me how...
The int() function converts your string number into a literal value
Once converted, it functions as any number would!
#Have the user enter their age
star_num = int(input("How Many Stars To Print?? "))
#Print the number of stars using string multiplication
print(star_num * "*")
The float() function converts your string number into a literal value
Once converted, it functions as any number would!
price = float(input("Enter the price of your item?? "))
quant = int(input("Enter the number of items: "))
print(f"The total price is: {price*quant}")
str( )
Converts something BACK to a string
Why do we need to??
use str() any time you need your number to behave like text (for display, concatenation, file names, logging, etc.), not as a numeric value.
This one turns values into Python True or False!! It's really useful when you want to have it displayed in a chart!
The Minions are planning a huge party for Scarlett Overkill and need your help calculating how much it will cost to feed all the Minions! You'll gather some information about the party, do some math to figure out the total number of bananas needed, and then calculate how much the bananas will cost. Let’s see if you can help the Minions avoid breaking the bank!
You will ask the user for the following information:
Number of Minions attending the party.
Number of bananas each Minion will eat.
Cost per banana (in dollars).
Scarlett’s banana tax (because of course, she adds a tax to everything).
You'll then:
Calculate the total number of bananas needed.
Calculate the total cost of the bananas.
Calculate Scarlett’s tax and add it to the total cost.
Display a fun, whimsical summary of the party banana budget.
See if you can change the output above to be something a bit nicer. Maybe something like these examples... Just for reference! They don't contain all the information!!!
REMEMBER... These are just EXAMPLES!!!
EVERYONE SHOULD MAKE AN ATTEMPT AT THIS!!!
Gru and the Minions are planning to produce a series of high-tech gadgets, but they need to manage the production details to ensure everything runs smoothly. Your task is to help them calculate key production metrics by gathering input from the user and performing various operations with different types of data.
You will ask the user for the following information:
Number of gadgets to be produced (integer).
Cost per gadget (float).
Materials cost per gadget (float).
Labor cost per gadget (float).
Is this a priority production run? (True/False).
Is this a special order? (True/False).
Is this an eco-friendly production? (True/False).
Does the gadget require a safety inspection? (True/False).
Total hours available for production (float).
How much energy each gadget consumes in kilowatts (float).
You'll then:
Calculate the total production cost by adding the cost per gadget, materials cost, and labor cost.
Determine the total energy needed for production by multiplying the energy consumption by the number of gadgets.
Calculate the average energy consumption per hour by dividing the total energy by the total hours available for production.
Display a formatted, whimsical summary of the production details, including all the values converted to the appropriate types (e.g., string, float, int, etc.).
HINTS:
Convert all inputs to their proper types (int, float, bool, and str).
Calculate the total production cost by summing up all costs.
Determine the total energy required for production.
Adjust the production summary by directly handling the boolean values using string casting (str()).