i am trying to print out this simply equation, but it says float object is not callable [closed] - python

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 2 years ago.
Improve this question
I have been trying to print out this very simple equation but I cannot figure out why it will not print?
fc = float(input("first cycle is "))
fp = float(input("first percent is "))
sc = float(input("second cycle is "))
sp = float(input("second percent is "))
tc = float(input("third cycle is "))
tp = float(input("third percent is "))
mem = float(input("the memory is "))
first_part = (fc * fp + (sc(1-fp)))
print(first_part)
It gives me the error "TypeError: 'float' object is not callable"

The * multiplication operator cannot be omitted as it can in an algebraic equation. The interpreter thinks sc(1-fp) is a function call.
first_part = (fc * fp + (sc * (1-fp)))

Related

max function not returning right ouput [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 2 months ago.
Improve this question
(I am pretty new to python)
Hey guys, so I was trying to code a simple python program which finds the HCF of two numbers, but I am getting an error when the two numbers are co-prime and the actual HCF is not showing for the two numbers
(Ex: The HCF for 12 and 24 should be 12 but python is showing 4
Here is the code, can any of you guys help me?
factors = []
print("Enter first number")
num1 = int(input())
print("Enter second number")
num2 = int(input())
if num1 < num2:
lesser = num1
else:
lesser = num2
for i in range(2, lesser + 2):
if num1 % i == 0 and num2 % i == 0:
factors.append(i)
if not factors:
print(num1, "and", num2, "are co-prime numbers, so they don't have any common factors")
str_factors = ', '.join(map(str, factors))
hcf = max(str_factors)
print(hcf)
You are turning factors into a comma separated string and using max on the string. It's giving you the max of the string lexicographically. You need to use max on the factors variable.
Say for a string '2, 12, 42, 13' max will return '4' because it loops through all characters in a string
Fix this line and it should produce you expected output
hcf = max(factors)

Write a python program to accept a number from a user and then calculate the average of all [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 3 months ago.
Improve this question
Write a python program to accept a number from a user and then calculate the average of all numbers from 1 to that given number. Then write the trace table to track the values of the variables at each iterate.
This is my attempt:
Range=int(input("ee: "))
Sum=0
Average=0
for i in range(1,Range):
sum=sum+i
Average=sum/i
print(Average," ",i)
I get an error on line 4.
sum is a keyword, you meant to use Sum (The variable you declared) in line 5 and 6.
Range=int(input("ee: "))
Sum=0
Average=0
for i in range(1,Range + 1):
Sum=Sum+i
Average=Sum/i
print(Average," ",i)
Also notice I have made it Range + 1. This is because the limit is not inclusive in the range() function.
You could also make the code a little compact like this:
count = int(input("ee: "))
total = sum(range(1, count + 1))
average = total / count
print(average)
Or just
count = int(input("ee: "))
average = sum(range(1, count + 1)) / count
print(average)

I dont know whats wrong, SyntaxError: unexpected EOF while parsing [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 10 months ago.
Improve this question
num1 = float(input())
num2 = float(input())
soma = (num1 * 3.5 + num2 * 7.5) / (2 * 10)
print(f'MEDIA = {soma.:5}')
...fails with:
RUNTIME ERROR
File "<fstring>", line 1
(soma.)
^
SyntaxError: unexpected EOF while parsing
Please visit this link for more info about string formatting in python
num1 = float(input())
num2 = float(input())
soma = (num1 * 3.5 + num2 * 7.5) / (2 * 10)
print(f'MEDIA = {soma:.5f}')
Output:
$ python3.10 main.py
3
4
MEDIA = 2.02500

TypeError: 'int' object is not callable (While working on google colaboratory) [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 last year.
Improve this question
In python I got a "TypeError: 'int' object is not callable" during execution.
I had read other posts but I still can't figure out why it is like this.
# Python code to find if a number is
# prime or not using divmod()
# Given integer
n = int(input("Enter a number"))
x = n
# Initialising counter to 0
count = 0
while x != 0:
p, q = divmod(n, x)
x -= 1
if q == 0:
count += 1
if count > 2:
print(n, 'is Not Prime')
else:
print(n, 'is Prime')
And, please note that it doesn't gives any error by replacing:
n = int(input("Enter a number")) to n = int(input("Enter a number"))
I have also provided a screenshot regarding my problem 👇
image
Answer if anybody knows, Appreciation for any suggestions and comments.
Have you tried something like this?
z = input("Enter a number")
n = int(z)
x = n

How to fix a while syntax error in python? [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 4 years ago.
Improve this question
I'm getting a syntax error on my 2nd while loop. Can't figure out why, any help appreciated :)
#intro
print("Welcome to my prime number detector.")
print("Provide an integer and I will determine if it is prime.")
#again loop
again = "Y"
while again == "Y":
num = (int(input("Enter an integer"))
#check for valid input
while num < 1:
num = (int(input("Enter an integer"))
#test for prime
for d in range(2,num):
if (num % d) == 0:
print(num,"is not prime.")
else:
print(num,"is prime.")
#ask again
again = intput("Do you want to play again? (Y/N)")
You are missing a closing parenthesis ) in the two of your following lines. The correct line of code is
num = (int(input("Enter an integer")))
Also, as sheepez mentioned below, your outer brackets are redundant. You can simply use
num = int(input("Enter an integer"))

Categories