Help pls/ python | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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)

21st May 2024, 3:41 PM
Matt
Matt - avatar
17 ответов
+ 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.
21st May 2024, 3:47 PM
Toni Isotalo
Toni Isotalo - avatar
+ 9
friends = int(input()) candles = friends/2
21st May 2024, 5:49 PM
Santanu
+ 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.
24th May 2024, 5:56 AM
Lothar
Lothar - avatar
+ 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.
21st May 2024, 4:07 PM
Per Bratthammar
Per Bratthammar - avatar
+ 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.
21st May 2024, 7:26 PM
Lothar
Lothar - avatar
+ 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
23rd May 2024, 12:55 PM
Pranit Prakash Deshmukh
0
Fixed, thanks.
21st May 2024, 4:03 PM
Matt
Matt - avatar
0
Thanks :)
21st May 2024, 5:00 PM
Matt
Matt - avatar
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.
22nd May 2024, 2:09 PM
Aryan Kadam
Aryan Kadam - avatar
0
Python is the best!!!! and he is great. Also, I can code a bit.
22nd May 2024, 6:30 PM
Aurelius
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.
22nd May 2024, 6:32 PM
Aurelius
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.
22nd May 2024, 6:32 PM
Aurelius
0
You can devide string by integer, make friends = input() to int(input()) and change the variable input to friends
22nd May 2024, 7:25 PM
Alen Gevorgyan
Alen Gevorgyan - avatar
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
26th May 2024, 11:35 AM
Mallikarjun M
Mallikarjun M - avatar
0
Hi guys
26th May 2024, 2:49 PM
Aurelius
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
30th May 2024, 7:41 PM
Haji Abdirahim Ali
Haji Abdirahim Ali - avatar
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
1st Jun 2024, 3:21 PM
camilo
camilo - avatar