Hi everyone,
I have just programmed a very very simple calculator program, I am actually rather pleased. I would just like to know how I can make it so that every time the user has entered their input and an output has been returned by the program, the program jumps back to the start and ask the user to choose another option. Here is the code for my very very simple calculator program. -
# my first very simple calculator
-
# this program only does basic arithmatic
-
-
print\
-
"""
-
#-------------#
-
# MYCALC 1.0 #
-
#-------------#
-
-
WELCOME TO MYCALC 1.0 This is a command line program that you can use
-
as a calculator just incase you don't have one installed on your
-
desk top. Using it is pretty self explanitory.
-
"""
-
print " You have the following options:\n"
-
options = ('addition = 1','subtraction = 2', 'division = 3', 'multiplication = 4',)
-
-
print "\nHere are ur options:\n", options
-
-
-
choice = int(raw_input("Plese enter your operation choice: "))
-
-
if choice == 1:
-
a = int(raw_input("enter value a: "))
-
b = int(raw_input("enter value b: "))
-
total = a+b
-
print "\nThe total is:", total
-
-
-
elif choice == 2:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a-b
-
print "\nThe total is:", total
-
-
-
elif choice == 3:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a/b
-
print "\nThe total is:", total
-
-
-
elif choice == 4:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a*b
-
print "\nThe total is:", total
-
-
else:
-
print "\nYour choice is invalid"
-
-
-
-
raw_input("\nPres enter to exit.")
-
-
-
-
-
-
-
Thanks, -Deathwing
2 1258 bvdet 2,851
Expert Mod 2GB
Hi everyone,
I have just programmed a very very simple calculator program, I am actually rather pleased. I would just like to know how I can make it so that every time the user has entered their input and an output has been returned by the program, the program jumps back to the start and ask the user to choose another option. Here is the code for my very very simple calculator program. -
# my first very simple calculator
-
# this program only does basic arithmatic
-
-
print\
-
"""
-
#-------------#
-
# MYCALC 1.0 #
-
#-------------#
-
-
WELCOME TO MYCALC 1.0 This is a command line program that you can use
-
as a calculator just incase you don't have one installed on your
-
desk top. Using it is pretty self explanitory.
-
"""
-
print " You have the following options:\n"
-
options = ('addition = 1','subtraction = 2', 'division = 3', 'multiplication = 4',)
-
-
print "\nHere are ur options:\n", options
-
-
-
choice = int(raw_input("Plese enter your operation choice: "))
-
-
if choice == 1:
-
a = int(raw_input("enter value a: "))
-
b = int(raw_input("enter value b: "))
-
total = a+b
-
print "\nThe total is:", total
-
-
-
elif choice == 2:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a-b
-
print "\nThe total is:", total
-
-
-
elif choice == 3:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a/b
-
print "\nThe total is:", total
-
-
-
elif choice == 4:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a*b
-
print "\nThe total is:", total
-
-
else:
-
print "\nYour choice is invalid"
-
-
-
-
raw_input("\nPres enter to exit.")
-
-
-
-
-
-
-
Thanks, -Deathwing
You do not need recursion - you need a while loop: - # my first very simple calculator
-
# this program only does basic arithmatic
-
-
print\
-
"""
-
#-------------#
-
# MYCALC 1.0 #
-
#-------------#
-
-
WELCOME TO MYCALC 1.0 This is a command line program that you can use
-
as a calculator just incase you don't have one installed on your
-
desk top. Using it is pretty self explanitory.
-
"""
-
print " You have the following options:\n"
-
options = ('addition = 1','subtraction = 2', 'division = 3', 'multiplication = 4', 'exit = 5')
-
-
print "\nHere are ur options:\n", options
-
-
while True:
-
choice = int(raw_input("Plese enter your operation choice: "))
-
-
if choice == 1:
-
a = int(raw_input("enter value a: "))
-
b = int(raw_input("enter value b: "))
-
total = a+b
-
print "\nThe total is:", total
-
-
-
elif choice == 2:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a-b
-
print "\nThe total is:", total
-
-
-
elif choice == 3:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a/b
-
print "\nThe total is:", total
-
-
-
elif choice == 4:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a*b
-
print "\nThe total is:", total
-
-
elif choice == 5:
-
break
-
-
else:
-
print "\nYour choice is invalid"
-
-
raw_input("\nPress enter to exit.")
If the user enters '5', the code 'breaks' out of the loop.
You do not need recursion - you need a while loop: - # my first very simple calculator
-
# this program only does basic arithmatic
-
-
print\
-
"""
-
#-------------#
-
# MYCALC 1.0 #
-
#-------------#
-
-
WELCOME TO MYCALC 1.0 This is a command line program that you can use
-
as a calculator just incase you don't have one installed on your
-
desk top. Using it is pretty self explanitory.
-
"""
-
print " You have the following options:\n"
-
options = ('addition = 1','subtraction = 2', 'division = 3', 'multiplication = 4', 'exit = 5')
-
-
print "\nHere are ur options:\n", options
-
-
while True:
-
choice = int(raw_input("Plese enter your operation choice: "))
-
-
if choice == 1:
-
a = int(raw_input("enter value a: "))
-
b = int(raw_input("enter value b: "))
-
total = a+b
-
print "\nThe total is:", total
-
-
-
elif choice == 2:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a-b
-
print "\nThe total is:", total
-
-
-
elif choice == 3:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a/b
-
print "\nThe total is:", total
-
-
-
elif choice == 4:
-
a = int(raw_input("\nenter value a: "))
-
b = int(raw_input("\nenter value b: "))
-
total = a*b
-
print "\nThe total is:", total
-
-
elif choice == 5:
-
break
-
-
else:
-
print "\nYour choice is invalid"
-
-
raw_input("\nPress enter to exit.")
If the user enters '5', the code 'breaks' out of the loop.
ah... ic ic okay, I'll take a look and see what happens gracias.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stevey |
last post by:
I have the following XML file...
<?xml version="1.0"?>
<animals>
<animal>
<name>Tiger</name>
<questions>
<question index="0">true</question>
<question index="1">true</question>
</questions>
|
by: nospam |
last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types,
so, since it seems to me that Partial Types is still in the design or
development stages at Microsoft, I am going to ask...
|
by: Ekqvist Marko |
last post by:
Hi,
I have one Access database table including questions and answers. Now
I need to give answer id automatically to questionID column. But I
don't know how it is best (fastest) to do?
table...
|
by: codefixer |
last post by:
Hello:
I am trying to understand why one of these crash while the other works
fine.
long recurssion(int t)
{
if(t <= 1)
return(1);
else
return(t * recurssion(t--)); //crashes
|
by: glenn |
last post by:
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can
get to their values easily to write to a...
|
by: Rider |
last post by:
Hi, simple(?) question about asp.net configuration..
I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm
first start application the follow message shown.
=========
Server...
|
by: Jeff |
last post by:
In the function below, can size ever be 0 (zero)?
char *clc_strdup(const char * CLC_RESTRICT s)
{
size_t size;
char *p;
clc_assert_not_null(clc_strdup, s);
size = strlen(s) + 1;
|
by: spibou |
last post by:
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a * (b+c)" or "a = a * b+c" ?
|
by: Allan Ebdrup |
last post by:
Hi,
I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix
question is a question where you have several options that can all be rated
according to several possible ratings (from...
|
by: Zhang Weiwu |
last post by:
Hello!
I wrote this:
..required-question p:after {
content: "*";
}
Corresponding HTML:
<div class="required-question"><p>Question Text</p><input /></div>
<div...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |