Python Forum

Full Version: Int error on line 70
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import time
import os
import sys
import colorama
from colorama import Fore, Back, Style

cm = input(Fore.GREEN + "please enter your current usage for main: "+ Fore.WHITE)
time.sleep(0.5)
os.system("clear")
cma = input(Fore.GREEN + "please enter your current usage for marina: "+ Fore.WHITE)
time.sleep(0.5)
os.system("clear")
ca = input(Fore.GREEN + "please enter your current usage for annette: "+ Fore.WHITE)
time.sleep(0.5)
os.system("clear")
pm = input(Fore.GREEN + "please enter the previous usage for main: "+ Fore.WHITE)
time.sleep(0.5)
os.system("clear")
pma = input(Fore.GREEN + "please enter the previous usage for marina: "+ Fore.WHITE)
time.sleep(0.5)
os.system("clear")
pa = input(Fore.GREEN + "please enter the previous usage for annetta: "+ Fore.WHITE)
time.sleep(0.5)
os.system("clear")
cm = int(cm)
pm = int(pm)
cma = int(cma)
pma = int(pma)
ca = int(ca)
pa = int(pa)
mu = cm - pm
mau = cma - pma
au = ca - pa
su1 = mau + au
su2 = mu - su1
mu = str(mu)
mau = str(mau)
au = str(au)
su2 = str(su2)
print(Fore.GREEN + "your usage for main is " + mu)
print(Fore.GREEN + "your usage for marina is " + mau)
print(Fore.GREEN + "your usage for annette is " + au)
print(Fore.GREEN + "your usage for the shop is " + su2)
time.sleep(5)
os.system("clear")
print(Fore.GREEN + "now calulating the Percentage's")
time.sleep(3)
os.system("clear")
mau = int(mau)
mu = int(mu)
au = int(au)
su2 = int(su2)
maper = mau / mu
aper = au / mu
sper = su2 / mu 
maper = str(maper)
aper = str(aper)
sper = str(sper)
print(Fore.GREEN + "marina's percentage of use is " + maper)
print(Fore.GREEN + "annetta's percentage of use is " + aper)
print(Fore.GREEN + "the shop's percentage of use is " + sper)
time.sleep(5)
os.system("clear")
bill = input(Fore.GREEN + "please enter the total cost of your bill" + Fore.WHITE)
time.sleep(3)
os.system("clear")
print(Fore.GREEN + "now calculating the amount due for each person: ")
time.sleep(3)
os.system("clear")
bill = int(bill)
maper = int(maper)
aper = int(aper)
sper = int(sper)
madue = maper * bill
adue = aper * bill
sdue = sper * bill
madue = str(madue)
adue = str(adue)
sdue = str(sdue)
print(Fore.GREEN + "Marina need to pay " + madue)
print(Fore.GREEN + "annette need to pay " + adue)
print(Fore.GREEN + "the shop needs to pay " + sdue)
SO i am making a program for my grampa that calculates his energy bill for him and i am having a problem converting a the bill cost from a str to a int on line 70 it keeps giving me a value error and i cant fix it the number i have been using to test the bill cost is 157.54 if that has anything to do with it so can any of you please help
Right before line 70 print(bill) and print(type(bill)). That may give a clue. Looks like that line should not give an error.
If you want to be able to enter 157.54 you need to convert to a float instead of an int
bill = float(bill)
Don't repeat yourself (DRY)

Think how you can change your code, to remove repeating code. Hint: loops, data structures. You may also break your code into small reusable chunks - functions