Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie error
#1
Im newb to python, can someone help me?
this error
can't multiply sequence by non-int of type 'str'

my code
n,T,P=input("input n, T, P").split()
R = 80
Luas = n*R*T/P
print("Luas = ({}*{}*{})/{}={}".format(n,R,T,P, Luas))
Reply
#2
The input function returns a string, as indicated by the fact that you can split it as you did on line 1. If you want to use n, T, and P as numbers, you need to convert them to numbers with the int() or float() built-ins.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Sep-22-2019, 02:33 PM)ichabod801 Wrote: The input function returns a string, as indicated by the fact that you can split it as you did on line 1. If you want to use n, T, and P as numbers, you need to convert them to numbers with the int() or float() built-ins.

can you give me an example code?
Reply
#4
n = int(n)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
(Sep-22-2019, 02:50 PM)ichabod801 Wrote:
n = int(n)
THANK YOU!! Big Grin
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NEWBIE error regarding syntax rohitn12 1 2,330 Dec-19-2017, 10:19 PM
Last Post: micseydel
  newbie while loop error: IndexError: list assignment index out of range msa969 3 75,049 Mar-31-2017, 12:24 PM
Last Post: msa969

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020