how do i ask multiple questions in python? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

how do i ask multiple questions in python?

I want to use input() and then use it again to define a different variable but i am unsure how, i always receive an error ex: https://code.sololearn.com/cMIHvN9u69JZ/?ref=app

30th Nov 2023, 5:21 PM
Erin
Erin - avatar
7 Antworten
+ 4
Hi, your code is correct (apart from the typo) but the codespace can only take input once per program. You will need a separate editor to run that code, are you using a desktop or mobile? There are loads of code editors available for either. I use VSCode on desktop and Pydroid / Cxxdroid on my phone.
30th Nov 2023, 5:30 PM
StuartH
StuartH - avatar
+ 6
Yes, I agree it is limited but it makes us come up with creative ways to accept input 😉 https://code.sololearn.com/ckn3jO4yuPJq/?ref=app A more beginner friendly version: https://code.sololearn.com/cvTdHZl4gpl1/?ref=app
30th Nov 2023, 6:38 PM
Keith
Keith - avatar
+ 6
(this sample is not meant to use with sololearn, but with regular ide's.) Keith , please allow me to use your code sample to do a modified try like: input like "Bob 2.17" (return) "Liz 4.94" (return ...). input ends if no input is given but just *return* is pressed. the input is splitted and then passed as argument to append(). if __name__ == '__main__': records = [] while inp := input().split(): records.append([inp[0], float(inp[1])]) print(records)
30th Nov 2023, 7:15 PM
Lothar
Lothar - avatar
+ 4
The Sololearn platform can accept multiple inputs. Just enter each input on a separate line as stated when the input window pops up 👍
30th Nov 2023, 6:21 PM
Keith
Keith - avatar
+ 2
Keith That slipped my mind, but worth noting this won't work if it repeats in something like a loop though. It will only ask once. It also doesn't allow you to practice using prompts for different information! Its pretty limiting.
30th Nov 2023, 6:25 PM
StuartH
StuartH - avatar
+ 2
That's a nice solution, as long as you know all your data at the outset and don't want any trial and error or multiple attempts at something. Neat code though 👌
30th Nov 2023, 6:47 PM
StuartH
StuartH - avatar
+ 1
yup! usefull code but isnt exactly what i am looking for, my goal is to do something like "square or triangle" then ask the base/height so that the output is only the area of the triange (or something else of that vein)
30th Nov 2023, 8:08 PM
Erin
Erin - avatar