Can anyone help me fix the code , please ! | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 3

Can anyone help me fix the code , please !

I've created this first python project , but I got a error (even though I did the same code in visual studio code , it was working perfectly there , but not here) https://sololearn.com/compiler-playground/c79xgL8hDiwG/?ref=app

20th Apr 2024, 4:54 PM
Miyamura
24 ответов
+ 4
Here, in sololearn you have to provide all the inputs first like when you run the code it asks for inputs you have to fill all the inputs in the cell like: 1 2 3 ..... And so on
20th Apr 2024, 5:47 PM
Ayush
Ayush - avatar
+ 3
Thanks everyone for helping 😃
21st Apr 2024, 5:12 AM
Miyamura
+ 1
It's not opening
20th Apr 2024, 6:03 PM
Miyamura
+ 1
Mahi This code playground requires all inputs upfront, which might cause issues with your code since it needs guesses and the number of inputs can vary.
20th Apr 2024, 6:32 PM
Chris Coder
Chris Coder - avatar
+ 1
Mahi If you add a break to line 22 it will stop the code from running as soon as it finds the number. Currently your code requires 11 inputs 2 4 9 11 13 15 16 17 18 19 20 Submit https://sololearn.com/compiler-playground/c1MrcBeeIcaG/?ref=app
20th Apr 2024, 6:46 PM
Chris Coder
Chris Coder - avatar
+ 1
It seems like the issue might be related to the condition in the while loop. It's set to `while count <= 10`, which means it will run until `count` becomes greater than 10, giving you an extra guess. To fix this, you can change it to `while count < 10` so that it runs until the 10th guess.
21st Apr 2024, 9:58 AM
Suhani Kewat
Suhani Kewat - avatar
+ 1
Try this import random def guess_the_number(): num = random.randint(0,20) count = 0 print("You have to guess a number within 10 guesses") while count < 10: # Changed condition to count < 10 guess = int(input("Enter your guess: ")) if guess > num: print("Try again, the guess is too big") elif guess < num: print("Try again, the guess is too small") elif guess == num: print("Congratulations! You found the number.") print("You found the number in", count + 1, "guesses") # Added 1 to count since indexing starts from 0 break count += 1 else: print("Sorry, you've run out of guesses. The number was:", num) guess_the_number()
21st Apr 2024, 9:58 AM
Suhani Kewat
Suhani Kewat - avatar
0
its true, it runs in VSCodium, but the 3rd guess is not equal with 2 guesses
20th Apr 2024, 5:40 PM
Mihaly Nyilas
Mihaly Nyilas - avatar
0
Sorry , but I didn't get you
20th Apr 2024, 5:44 PM
Miyamura
0
Ohh , means I have to create many variables for many inputs
20th Apr 2024, 5:49 PM
Miyamura
0
Mahi I don't think just type the all inputs in the input box asked when going to run.
20th Apr 2024, 5:52 PM
Ayush
Ayush - avatar
0
I'm still not getting it 😅
20th Apr 2024, 5:54 PM
Miyamura
0
Actually , all the error comes is , the input , it asks one time - it doesn't matches , and now it should ask again but it didn't ask and gives a error
20th Apr 2024, 5:55 PM
Miyamura
0
I did a little change but still error is at the input , I think I have to change the code itself
20th Apr 2024, 6:00 PM
Miyamura
20th Apr 2024, 6:01 PM
Ayush
Ayush - avatar
0
I have found the problem, the problem is not with your code, the problem is with how sololearn asks for user input(that's why it worked with visual studio and will work with python if you install it). On this app your guess game is pointless, because it asks for user input only once, so you can win it literaly by just typing 1-20 in every row. You can try running yr code here https://www.online-python.com/ .
20th Apr 2024, 8:28 PM
𝙸𝚋𝚎𝚕𝚒𝚗𝚊 𝙻𝚎𝚘
𝙸𝚋𝚎𝚕𝚒𝚗𝚊 𝙻𝚎𝚘 - avatar
0
Mahi Actually you are dealing with two types of Errors in your code for two types of inputs. First is when your input is e.g. 1 3 5, it shows ValueError: invalid literal for in() with base 10: '1 3 5'. Lets deal with it first, it occurs because the program expects a single integer input for each guess, but when you input multiple numbers separated by spaces, it tries to convert the entire string (including spaces) to an integer, resulting in a 'ValueError'. To resolve this issue, you can modify the program to handle multiple guesses entered in a single line, splitting the input string into individual guesses and processing them one by one. [ Next ⤵️ ]
20th Apr 2024, 9:39 PM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar
0
Mahi Second is when your input is e.g. 1 3 5, it show EOFError: EOF when reading a line. The EOFError likely occurs because the program expects the user to input guesses within the while loop, but the input stream is closed unexpectedly, causing the program to encounter the end of the file EOF. To resolve this error and prevent the program from crashing, you can catch the EOFError and handle it gracefully by displaying an appropriate message. Our Sololearn, executes the code & captures any runtime errors that occur during execution. This includes errors like ValueError or EOFError that happen when the program runs into unexpected input or reaches the end of a file prematurely. This is definitely for educational purpose to teach how to handle errors professionally. To resolve these errors remember those tricks, I already debugged a lot of codes with those issues. Here is your code after resolving those errors. Enjoy and Happy Coding! https://sololearn.com/compiler-playground/c6pVUrhMF7K5/?ref=app
20th Apr 2024, 9:40 PM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar
0
Suhani it's showing same error. If wanna free your compiler out of Errors, you need to use my tricks here!
21st Apr 2024, 11:09 AM
`нттp⁴⁰⁶
`нттp⁴⁰⁶ - avatar
0
Hey any one can help me to create game codes
21st Apr 2024, 12:01 PM
Kalamu Joel
Kalamu Joel - avatar