make a calculator that calculates the volume of a cube [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am new to python and my problem is when I want to make a calculator that calculates the volume of a cube:
>>> print(int ** 3 (input ("Enter the side length: ")))
Enter the side length: 4
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
print(int ** 3 (input ("Enter the side length: ")))
TypeError: 'int' object is not callable

The int() function should wrap around the whole input() function, Something like this
print(int(input('Enter the side length:')) ** 3)

Related

get an integer from a user and find the next larger integer that is multiple of 10 [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am going to get a number from a user and find the nearest number that is larger and multiple to 10. Here is my code:
n = int(input(''))
n + (10 - n%10)
but when I run it I come across this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: n + (10 - n%10)
What am I doing wrong?
My python version is 3.9.6
Your code works like it is supposed.
The problem is that you didn't input an integer and instead inputted your second line:
n + (10 - n%10)
P.S.: I would consider changing your code to the following, it uses only one line instead of two, but that's up to you:
n = int(input(''))//10*10+10
It seems that you are giving the mathematical expression as input, rather than a number. When you call input and wrap it with int(), python expects to take the input and convert it to a number which belongs to base 10. Obviously any non-numeric string doesn't belong to base 10.
So you should write the second line after the input one, and wrap it with a print() to display the result. If you are writing this in the interpreter, then you should immediately provide the number you want to test, and then give python the math expression to calculate

Python NameError: name ' ' is not defined [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i am inputting simple code into IDLE but it keeps telling me after I run the simple program that a word to check how many vowels is not defined.
def search4vowels(word):
'''Return a boolean bassed on any vowels found.'''
vowels = set('aeiou')
return vowels.intersection(set(word))
Error Message
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
gal
NameError: name '' is not defined
I think you call your function like this:
search4vowels(gal).
Try calling it like this: search4vowels("gal").
You have to enclose strings in quotes, otherwise python is looking for a variable called gal (In your example).
gal is not defined==>Error

Just started Intro to Python an have no previous knowledge about coding-That being said Professors rubric didn't explain anything any ideas [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Traceback (most recent call last):
File "challenges/str.py", line 7, in <module>
result = 'a string combined with the number: ' + aString
TypeError: Can't convert 'int' object to str implicitly
Due to the lack of code, no explanation, it seems to me that the aString object is an integer.
To fix this, the line with error should become:
result = 'a string combined with the number: ' + str(aString)
Hopefully, this helps!

what is my mistake in the code and why is that error for? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So basically I have to write a code which tells the user to input numbers (as variables I named them number1, number2, number3 ...) until I get the answer of zero once you add each number that they inputted then which the sum is equal to zero I should print how many numbers they inputted so the answer they got was zero, now the main thing is that I know how to write that code but there is an error that I get:
Traceback (most recent call last):
File "Solution.py", line 13, in <module>
sys.exit()
NameError: name 'sys' is not defined
Maybe try using
from sys import *
and just use exit(0) when you want to sys.exit()

Error with pow: "can't convert complex to float" [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i have this problem with my Python code :
from math import *
m = pow(complex(1,2)*complex(3,0) + complex(1,0),complex(-1,0));
TypeError: can't convert complex to float
Does anyone know how to solve this problem ?
Thanks a lot !
The problem is that you are using from math import *. This shadows the built-in pow with a version that doesn't support complex numbers.
>>> pow(1+1j, 1)
(1+1j)
>>> import math
>>> math.pow(1+1j,2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
from <x> import * is usually considered bad practice, and cases like this are why.
Instead, you should use import math, and reference all your math functions as, e.g. math.sqrt
Alternatively, you can use ** instead of pow:
>>> 1j ** 2
(-1+0j)

Categories