I am still new to Python and programming and StackOverflow, please excuse my lack of proper coding vocab. My problem is the code below. I can run both while True loops just fine, but as soon as it reaches the code under the comment #PROBLEM STARTS HERE, I have no idea what exactly am I doing wrong. The error message I got is unsupported operand type(s) for /: 'str' and 'int'.
gameName = str(input('Enter game title: '))
while True:
basePrice = input('Enter the base price: ')
try:
check = float(basePrice)
break
except ValueError:
print('Please enter a valid price.')
continue
while True:
discountPtg = input('Enter the discount(%): ')
try:
check = float(discountPtg)
break
except ValueError:
print ('Please enter just a number for your discount.')
#PROBLEM STARTS HERE
disctdPrice = (discountPtg / 100) * basePrice
savedCost = basePrice - disctdPrice
print ('\nSTATS\n')
print (gameName)
print ('Base price: RM' + str(basePrice))
print ('Discount: ' + str(discountPtg) + '%')
print ('Discounted price: ' + str(disctdPrice))
print ('You saved: ' + str(savedCost))
Any help will be very appreciated.
You checked to see if it is a number, but you never converted it to one. On this line:
disctdPrice = (discountPtg / 100) * basePrice
DicountPtg should be turned into a float like this:
disctdPrice = (float(discountPtg) / 100) * basePrice