+ 4

Please find the mistake in following code

import random print("Hello there, what is your name?") name = input() print (name) import random print( name +" have to go to a path you can see two paths infront. write either 1 or 2 ") path=input() if path== 2: print ("you have fell into deep well you have died") if path== 1: print ("you have encountered a weakened soldier and you kill him")

24th Nov 2020, 10:36 AM
Dino Gupta
Dino Gupta - avatar
18 Réponses
- 2
Specifi the data type of name
25th Nov 2020, 6:33 PM
Darshan Pagar
Darshan Pagar - avatar
+ 10
Convert the path input to integer instead of string using path = int(input())
24th Nov 2020, 10:42 AM
Sudo
Sudo - avatar
+ 8
Why did you import random? (Twice)
24th Nov 2020, 10:47 AM
Sudo
Sudo - avatar
+ 6
if - elif - else statements? if path == 1: do smth else: do smth else for path != 1
24th Nov 2020, 10:58 AM
AlTairTech
AlTairTech - avatar
+ 6
a = int(input()) b = int(input()) print(a+b) # when you run program in sololearn # enter all input at once on diff lines 2 3 #then hit submit #output 5
24th Nov 2020, 12:20 PM
Slick
Slick - avatar
+ 4
Dino Gupta is it on sololearn playground?
24th Nov 2020, 11:01 AM
Sudo
Sudo - avatar
+ 3
Still not working
24th Nov 2020, 10:53 AM
Dino Gupta
Dino Gupta - avatar
+ 3
You have not used random and imported it twice. There is no need of random on your code.
26th Nov 2020, 3:08 AM
Aditya
Aditya - avatar
+ 2
Okay
24th Nov 2020, 10:42 AM
Dino Gupta
Dino Gupta - avatar
+ 2
Yes input(" ")
24th Nov 2020, 10:52 AM
Sudo
Sudo - avatar
+ 2
Dino Gupta use input (" ") not input()
24th Nov 2020, 10:52 AM
Sudo
Sudo - avatar
+ 2
https://code.sololearn.com/cJKzp0lVKR2G/?ref=app You can write it like this. This is what I have wrote after I saw your code. When you submit your response on sololearn playground, please make sure to first write your name and enter your number on the second line. Like it if you loved it. :))
26th Nov 2020, 9:58 AM
Endalk
Endalk - avatar
+ 1
It is showing eof error
24th Nov 2020, 10:44 AM
Dino Gupta
Dino Gupta - avatar
+ 1
What is its alternate of random. But the main problem is about input statement
24th Nov 2020, 10:51 AM
Dino Gupta
Dino Gupta - avatar
+ 1
I just want to know how to have more than one input in one program
24th Nov 2020, 10:58 AM
Dino Gupta
Dino Gupta - avatar
+ 1
you can change line 4 to " name = int(input()) " or you can change line 10 and 12 to "if path == '2': " and "if path == '1': "
26th Nov 2020, 5:38 AM
sujay simha
sujay simha - avatar
+ 1
use '2' instead of 2 in if path =='2' or convert into intger path =input path =int(path)
26th Nov 2020, 6:50 AM
FIFA_Monk
FIFA_Monk - avatar
0
If you want the input function run more than once,you can define your own function like "get_input",which include the input function,then use the infinite loop as follow: while True: get_input() Every time an input and output execution finished,it will wait another input. If you finished the Python3 OOP course here,you will learn.
25th Nov 2020, 1:57 PM
yingSSS['book'=="本"]