0% found this document useful (0 votes)
28 views5 pages

(English (Auto-Generated) ) Let's Code A Simple Python CALCULATOR! ? (DownSub - Com)

Uploaded by

rmorchid08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

(English (Auto-Generated) ) Let's Code A Simple Python CALCULATOR! ? (DownSub - Com)

Uploaded by

rmorchid08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

hey everybody this is a remake of my

python calculator program for absolute

beginners all you need to know to

complete this exercise is just if

statements and how they work so let's

get started for this exercise a user is

going to select an arithmetic Operator

Operator equals input we will ask the

user to enter an

operator this will be plus for addition

minus for subtraction as risk for

multiplication and a forward slash for

division

you could enter more than this but I

don't want to make this exercise too

complicated we will create a variable of

num one to contain our first number

let's say we would like to add two

numbers together what is the first

number going to

be enter the first

number and let's do this with the second

number num two enter the second

number let me show you something

I'm going to add num one and num two

together num one plus num two we'll do a

test

run enter an operator I would like to

use addition enter the first number 10

and 11 well the result is


101 when we accept user input they are

string data types what we've ended up

doing is string concatenation we've

concatenated the string of 11 to 10

that's why we ended up with 101 we'll

have to convert these two strings to be

floating Point numbers by typ casting

them as a

float so enclose your input functions

with a typ cast a flat and now we should

be able to add those two numbers

together so let's add 10 and 11 and we

get

21.0 depending on the operator that the

user selects we'll some if statements to

determine that we will check if our

operator variable is equal to a

character of

plus and for now I'll write pass as a

placeholder we'll get back to this later

else if our

operator is equal to minus we will use

subtraction and for now I'll write

pass Els if operator is equal to an

asterisk for

multiplication we will

multiply else if our operator is equal

to a forward slash for division we will

divide if our operator is addition let's


create a variable of

result result equals num 1 plus num

2 for

subtraction it's going to be num one

minus num

2 multiplication would be num 1 * num

2 then division would be num one / num

2 then we just have to print the result

print our

result be sure to do this with each of

the LF statements as

well and let's see what we have let's

add 5.5 +

6.9 that gives us 12.4

let's

subtract

420 minus

0.69 that gives us

41931 let's test

multiplication multiply

3.14 *

3.14 which gives us 9.85

n6 then

division let's

divide 69 by

13 and that gives us a really long

number so you could round a number if

you would like we would enclose our

result within the round

function and we'll just update each of


these print

statements this will round to the

nearest whole integer so let's divide

420 by

13 let's say that we would like three

digits after the decimal within the

round function we could add comma 3 for

three decimal

places enter an operator let's use

division divide 420 by

69 so that gives me

6.87 so we can round to a given digit

after a decimal in this case three

places what if somebody types in an

operator that doesn't exist like the

word

pizza then I will divide two numbers

well let's add an L statement if

somebody selects some input that is

invalid let's let them

know I'll use an F string let's say that

the operator that the user has

selected is not valid and let's try this

again enter an operator Pizza enter the

first number 420 and

69 Pizza is not valid let's say is not a

valid operator instead that makes more

sense pizza will be my

operator first number is 420 second


number is

69 Pizza is not a valid

operator all right everybody so that is

a very simple python calculator program

you can make as a beginner

You might also like