#πŸ”’ calculator trouble

93 messages Β· Page 1 of 1 (latest)

raven raft
#
#===[imports]===#
import time
#===============#

#===[inputs]===#
grams_per_cubic_centimeter=int(input("what is your papers GSM?:"))
time.sleep(1)
sheets_in_signiture=int(input("how many sheets are in your signature?:"))
time.sleep(1)
signatures_in_textblock=(input("how many signatures are in your block:"))
#==============#


#===[calculations]===#
textblock_grams=sheets_in_signiture*grams_per_cubic_centimeter*signatures_in_textblock

textblock_lbs=textblock_grams/453.6

#====================#


#===[prints]===#
time.sleep(1)
print("text block in grams",textblock_grams)
time.sleep(1)
print(" text block in pounds",textblock_lbs)

Error:
line 15, in <module>
textblock_lbs=textblock_grams/453.6

TypeError: unsupported operand type(s) for /: 'str' and 'float'

I honestly am lost on the problem here does anyone have any thoughts?

wary anvilBOT
#

@raven raft

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

normal niche
#

10th line btw

raven raft
#

i caugh it

normal niche
#

great

raven raft
#

any thing i sould add?

normal niche
#

signatures_in_textblock=int(input("how many signatures are in your block:"))

#

just an int

raven raft
#

remove input?

normal niche
#

no

raven raft
#

how could i make a 80-150 range for the gsm?

normal niche
#

u want the user to only enter no. btw 80-150?

raven raft
#

thank you zero

#

What do you think might need to be at it or changed?

normal niche
#

u can use conditional statements to stop the user from entering other numbers

raven raft
#

I only want it to be in a range like I mean anything higher because 150 is the highest grain of paper and 80 being the lowest and I want to make it so that people don't go over that and mess up the calculations so I don't know how to really make that into a piece of python code

#

My apologies

#

Zero?

normal niche
#

u have to learn how if and else work and implement it into ur program

raven raft
#

How would I Make It stop the loop if it encounters something wrong with the if statement?

flat forum
normal niche
raven raft
#

Witch line do I have to convert?

raven raft
#

Also how could make it start from the beginning of the code?

flat forum
#

signatures_in_textblock=input(...
->
signatures_in_textblock=int(input(...

raven raft
#

I actually fix that earlier sorry

#

But thank you

uneven shoal
#

why do u have those wierd ass comments

uneven shoal
#

they have like the brackets and dashes

#

what even is this

proven saddle
#

if they're new it might help with organisation

proven saddle
raven raft
#

i use them for organization

uneven shoal
proven saddle
raven raft
#
#===[imports]===#
import time
#===============#

#===[inputs]===#
grams_per_cubic_centimeter=int(input("what is your papers GSM?:"))
time.sleep(1)
sheets_in_signiture=int(input("how many sheets are in your signature?:"))
time.sleep(1)
signatures_in_textblock=int(input("how many signatures are in your block:"))
#==============#


#===[calculations]===#
textblock_grams=sheets_in_signiture*grams_per_cubic_centimeter*signatures_in_textblock

textblock_lbs=textblock_grams/453.6

#===[logic]===#
if grams_per_cubic_centimeter<80:
    print("not a valid input")
    
if grams_per_cubic_centimeter>150:
    print("not a valid input")
    
#====================#

#===[prints]===#
print("#===[final weight]===#")
time.sleep(1)
print("\n text block in grams",textblock_grams)
time.sleep(1)
print("\n text block in pounds",textblock_lbs)
time.sleep(1)
print("#=====================#")
#==============#
#

here's the updated code

proven saddle
#

u might want to move your input validatation logic to be right after inputs instead of calculating first pithink

unreal quarry
#

with how many sleeps you have, you might consider doing

from time import sleep

and then change the time.sleep to just sleep

#

doesnt change the function of your code just how id recommend importing sleep lol

proven saddle
unreal quarry
raven raft
#

thank you

unreal quarry
proven saddle
raven raft
#

lgtm?

proven saddle
#

looks good to me

raven raft
#

thank you

#

but how do i make it stop if the input on the gsm is not valid?

proven saddle
#

you could use a loop to prompt for input until gsm is valid, or terminate the program early using raise SystemExit (or sys.exit())

raven raft
#

how would that loop look like?

#

what i mean is were would the loop start and end?

proven saddle
raven raft
#

?

proven saddle
#

have you learned about loops in Python yet?

raven raft
#

little to none

proven saddle
#

ah

raven raft
#

my apoligys

proven saddle
#

a while loop will continuously run a block of code until a condition is true

#

with the following syntax:

#

!e ```python
count = 0
while count < 4: # loops while the value of count is less than 4.
print("looping")
count = count + 1

count equals 4, so the loop ends

print("no longer looping")

wary anvilBOT
proven saddle
raven raft
#

Well I like that idea but if I didn't looping that might cause a break

#

In the code

proven saddle
#

what do you mean by a break?

raven raft
#

Where there's two lines of code that conflict with each other or if I had another line of code it doesn't truly work with the one of the other lines of code and then I go to change that then the one I put in isn't saited then I have to put it back then get a computational error my apologies

proven saddle
#

what two lines are conflicting?

raven raft
#

Wear one line of code directly says that I can't have this line of code and then I have to change one part and then you get a computational error it can't have one without the other but that line of code doesn't want to go with that line of code sorry

#

Sorry

proven saddle
#

do you mean this code?

if grams_per_cubic_centimeter<80:
    print("not a valid input")
    
if grams_per_cubic_centimeter>150:
    print("not a valid input")
raven raft
#

Yes that's what I had originally but it doesn't print it as soon as it's goes through the input saying that it's invalid and ends up timesing it in the grams from all the math so that's why I'm trying to do make make it where it's a specific GSM more specific range()

#

My apologies

unreal quarry
#

well you can put it on one line
(even though they actually dont conflict)

if 80<grams_per_cubic_centimeter<150:
    print("not a valid input")
#

!e

x = 50
y = 90
z = 160
for value in (x,y,z):
  print(80<value<150)
wary anvilBOT
raven raft
#
#===[imports]===#
import time
#===============#

#===[inputs]===#
grams_per_cubic_centimeter=int(input("what is your papers GSM?:"))
time.sleep(1)
sheets_in_signiture=int(input("how many sheets are in your signature?:"))
time.sleep(1)
signatures_in_textblock=int(input("how many signatures are in your block:"))
#==============#


#===[calculations]===#
textblock_grams=sheets_in_signiture*grams_per_cubic_centimeter*signatures_in_textblock

textblock_lbs=textblock_grams/453.6

#===[logic]===#
if 80<grams_per_cubic_centimeter<150:
    print("not a valid input!!")
#=============#
#====================#

#===[prints]===#
print("#===[final weight]===#")
time.sleep(1)
print("\n text block in grams",textblock_grams)
time.sleep(1)
print("\n text block in pounds",textblock_lbs)
time.sleep(1)
print("#=====================#")
#==============#
#

What would I need to add to this code?

#

It's my code clean?

proven saddle
#

but aside from the input validation it is alright πŸ‘ single spaces after commas and between operators might help make the code easier to read.

raven raft
#

So what do I need to change or ADD to" GPCC"?

proven saddle
#

you can use 80 <= grams_per_cubic_centimeter <= 150 to check if the GSM is valid (eg. in a while loop). otherwise your original check worked fine.

raven raft
#

f 80<=grams_per_cubic_centimeter<=150:
print("not a valid input!!")
while loop()

wary anvilBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.