i have to write a code that tells the user to enter the amount of minutes they were allowed to use, it has to be between 200 and 800
if it exceeds or goes below then it should print
"please enter minutes between 200 and 800"

the problem is:
if the user enters a number less or above i dont know how to loop it to ask the question again. this is what i have so far

p.s. this would be the same problem with my def used(): as well,

def main():
minutes=mins()
use=used()
calctotal (use, minutes)
def mins():
mins = input("how many minutes are allowed")
if mins <200:
print "Please enter minutes between 200 and 800"
if mins >800:
print "Please enter minutes between 200 and 800"
return mins
def used():
used = input("how many minutes were used")
if used < 0:
print "enter minutes used of at least 0"
return used
def calctotal(use,minutes):
if use > minutes:
Over = (use - minutes)
print "you were over: ", Over
if use < minutes:
Over = 0
print "you were not over your minutes for the month"
Total = 74.99 + (Over * .2)
print "-----------------MONTHLY USE REPORT----------------"
print "Minutes allowed were" , minutes
print "Minutes used were" , use
print "Minutes over were" , Over
print "Total due is $" , Total
main()

Recommended Answers

All 5 Replies

Ugg. Double post. Sorry.

First of all, please wrap your code in code tags. It will save everybody on the forum a great deal of pain.

Anyways, back to your problem. Try replacing your "mins" function with this one:

def mins():
    mins = 0 # Initialize the variable
    while (mins > 800) or (mins < 200):
        mins = input("how many minutes are allowed")
        if mins <200:
            print "Please enter minutes between 200 and 800"
        if mins >800:
            print "Please enter minutes between 200 and 800"
    return mins

EDIT: Admins/moderators, how do you put a code tag in a reply without creating a code box?

with this code in mind, this does not apply to my other
def used() statement..
why does this not work?

def used():
used = 0
while (use < 0):
use = input("how many minutes were used")
if use < 0:
print "enter minutes used of at least 0"
return use

at the final it does not loop at all it uses my used and uses it as 0

The reason it is not working is because you are splitting it up into two different sections. You need to move your if statement inside the while loop. It should be like this:

def used():
    used = 0
    while (used < 0):
        used = input("how many minutes were used")
        if (used < 0):
            print "enter minutes used of at least 0"
    return used

edit: Admins/moderators, how do you put a code tag in a reply without creating a code box?

Hou can put spaces after the opening or before the closing [ ]

[/code ][code ]
[/code ]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.