Jump to content

how to multiplication two vareibles numbers


Recommended Posts

import math
import random
print("picle price is changing every day")
piclePrice = random.randint(3,9)
picleamount = input("Enter picle amounth:")
print(' price: '+piclePrice)
results = (picleamount*piclePrice)
#once i put amount i get the price
Link to comment
Share on other sites

  • 2 years later...

To multiply two variables in Python, both variables need to be of numeric types (e.g., integers or floats). In your code, the picleamount variable is being read as a string from the input function. You need to convert it to an integer or float before performing the multiplication.

Here is the corrected version of your script:

import random

print("Pickle price is changing every day")
pickle_price = random.randint(3, 9)
pickle_amount = int(input("Enter pickle amount:"))

print('Price per pickle:', pickle_price)

# Calculate the total price
total_price = pickle_amount * pickle_price
print('Total price:', total_price)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...