## Python Code Problem

Acid_1
Level 5
Posts: 795
Joined: Thu Nov 01, 2007 11:12 pm
Contact:

### Python Code Problem

While this started as a school assignment, it is now a personal one. I can't get the program to loop. I just get an error. If someone would look over my source, that'd be cool.

Code: Select all

`# calculates are for rectangles and circles them when providedwhile True:    print "welcome to the area calculation program"    print "--------------------------------------"    print    # print out out the menu:    # start        print "please select a shape:"    print "1 rectangle"    print "2 circle"    # user choice    shape = input(">")    # calculate area    if shape ==1:        height = input("please enter the height")        width = input("please enter the width")        area = height*width        print "the area is", area    else:        pi = input("define pi")        radius = input("please enter the radius:")        area = pi*(radius**2)        print "the area is", area    print "again?"    finished = input("y/n")    if finished(y): break`

It'd be much appreciated if someone could help me

ed@Mint
Level 5
Posts: 563
Joined: Sun Mar 09, 2008 6:03 pm
Location: Liege, Belgium

### Re: Python Code Problem

Hi Acid_1,

First, i'd like to say that Linux Mint forums are not the appropriate place to post about programming issues.
I suggest you to visit these forums : http://python-forum.org/pythonforum/index.php

Second, give the error message as well, instead of saying "i have an error"

Those were the errors :
1) prefer using the raw_input() function than input() in those cases. It works the same and always returns a string.
2) you forgot the quotes ' ' around the characters when you test it
3) you inverted the condition to end the program

I'll even post the corrected code, but please do take in advice what i said above.

Code: Select all

`# calculates are for rectangles and circles them when providedwhile True:   print "welcome to the area calculation program"   print "--------------------------------------"   # print out out the menu:   # start   print "please select a shape:"   print "1 rectangle"   print "2 circle"   # user choice   shape = raw_input(">")   # calculate area   if shape == '1':      height = input("please enter the height")      width = input("please enter the width")      area = height*width      print "the area is", area   else:      pi = input("define pi")      radius = input("please enter the radius:")      area = pi*(radius**2)      print "the area is", area   print "again?"   finished = raw_input("y/n")   if finished == 'n': break`

Hope you'll find what you were looking for with this...
cheers
ed
In libro veritas

Now switched to : ArchLinux

New users, read the Linux Mint User Guide | Problem ? See the Wiki first | Check out the Software Portal | Join the IRC channel : #linuxmint @ irc.spotchat.org

Acid_1
Level 5
Posts: 795
Joined: Thu Nov 01, 2007 11:12 pm