+ 1
Help pls/ python
What's the problem with this code? I wanna print the number of candles I need according to 'friends' + myself friends = input() candles = input/2 print(candles + 1)
17 odpowiedzi
+ 18
The error is at the second row.
input() returns a string to the friends variable.
At the second row, you need to replace the input/2 with friends/2.
But before that, you must convert the friends variable to integer using the int() function.
+ 9
friends = int(input())
candles = friends/2
+ 5
Pranit Prakash Deshmukh ,
it is not seen as very helpful when we are going to post a ready-made code.
it is more helpful to give hints and tips, so that the op has a chance to find a solution by himself.
+ 4
Hi, Matt!
In addition to what Toni Isotalo mentioned, it’s important to note that ‘candles’ is typically an integer. Therefore, instead of using ordinary division ‘/’ which returns a float, you can use integer division ‘//’ to get an integer result.
+ 3
Matt ,
if you are referring to the `code coach challenge *candles*` i have some doubts about the logic.
task description:
It is almost Hanukkah and the store in your town is completely out of candles! You decide to place an order online, and you talk to your friends to see who else needs candles. How many candles should you order in total for the holiday?
Task
Determine how many candles you need to order based on how many friends ask to join your order (each friend will need 9 candles).
Input Format
An integer that represents the number of friends that ask to order candles with you.
Output Format
An integer that represents the total number of candles that you need to order.
Sample Input
4
Sample Output
45
Explanation
If four of your friends ask you to order their candles for them, you will need 9 for each of them, and 9 for yourself. That's 45.
+ 1
This is the Answer:
# First take an input of how many Friends
friends = int(input())
#add yourself in that
total_People = friends + 1
total_candals = total_People * 9
print(total_candals )
use this Code
0
Fixed, thanks.
0
Thanks :)
0
HERE THIS CODE MIST BE GIVING AN
NameError as input is not defined. Matt the mistake you are making is that instead of carrying out the division operation on the candle variable you are carrying out it on input(which input defined in the code given by you).Fix it and it will work.
0
Python is the best!!!! and he is great. Also, I can code a bit.
0
The error is at the second row.
input() returns a string to the friends variable.
At the second row, you need to replace the input/2 with friends/2.
But before that, you must convert the friends variable to integer using the int() function.
0
HERE THIS CODE MIST BE GIVING AN
NameError as input is not defined. Matt the mistake you are making is that instead of carrying out the division operation on the candle variable you are carrying out it on input(which input defined in the code given by you).Fix it and it will work.
0
You can devide string by integer, make friends = input() to int(input()) and change the variable input to friends
0
Corrected Code
friends = int(input())
candles = friends/2
print(candles + 1)
input() returns string. But we need it to be an integer, therefore we converted the value returned by input() into integer using int() function. The value returned by int() is stored in friends, not input. So thats it.
References
https://programguru.org/JUMP_LINK__&&__python__&&__JUMP_LINK/how-to-convert-string-to-integer
https://programguru.org/online-compiler/python
0
Hi guys
0
by default input takes string so you should convert to int if you want arithmatic operation like this
friends = int(input()) # 6
candles = friends / 2 # 3
print(candles + 1 ) # 3 + 1
the output will become 4
0
first row take out the parentheses because it is a variable
2 row take out input just put 2
3 line is good I think