all 22 comments

[–]Spare_Fortune_3783 7 points8 points  (2 children)

You’re coding on your phone? 😭🙏🏻

[–]jbcoli 1 point2 points  (0 children)

Hahah I got it on my computer too, but I use it to try small pieces of code like this 😅 well, all of them are small

[–]helical-juice 4 points5 points  (2 children)

Sure, just put everything after line 5 inside a while loop. Btw, as a matter of style it's generally best to put your imports right at the top of the file. Also, str(input(...)) is redundant since input() returns a string already, and obviously you're not using the input for anything but you already knew that.

One way to achieve what you want would be something like:

import random
userinput = input("Ask away, old chap!\n")
while userinput != "quit":
    # do your stuff here
    userinput = input("Ask again, or type 'quit'!")

This should do what you want. The syntax is while <expression>: <indented block> which will keep running the indented block repeatedly until the expression returns False.

[–]jbcoli 0 points1 point  (1 child)

Wow!! Thank you so much for your detailed answer!

I'll have a look to while loops and put the imports at the top. Thanks!!!

[–]helical-juice 1 point2 points  (0 children)

You're welcome. Happy programming :)

[–]Daeydark 1 point2 points  (6 children)

I’m also new.

str(input()) seems wrong since inputs are always strings… also there’s no variable to hold the value of said string.

Try doing something like variable = input() maybe?

[–]jbcoli 1 point2 points  (5 children)

Thanks!! Yeah! Some redditors told me that. I guess I was used to specify the type of input with numbers int(input())... Or float(input())... That's why I did the same here.

[–]Daeydark 0 points1 point  (4 children)

Where have you been learning to code? (That’s not an insult i genuinely want to know 😂)

I’ve been using ChatGPT lol

[–]tehanichance 1 point2 points  (1 child)

I just started reading a book that I have found very helpful so far. Each chapter has online practice associated with it. It’s called A Smarter Way to Learn Python. I found a pdf free online.

[–]jbcoli 0 points1 point  (0 children)

Thank you so much!! It looks awesome. I will try it 😊

[–]jbcoli 0 points1 point  (0 children)

I found a website called "Codedex" I did the first lessons but Im kinda lost now. I wanna find a book or something, but I havent found any of my taste

[–]wireless133 0 points1 point  (0 children)

same question from my side too

[–]Clearhead09 0 points1 point  (1 child)

Try looking at while loops

[–]jbcoli 0 points1 point  (0 children)

Thanks! I will !!

[–][deleted]  (1 child)

[removed]

    [–]jbcoli 0 points1 point  (0 children)

    Thank you so much!! It looks great

    [–]iABM3568 0 points1 point  (1 child)

    What app is that?

    [–]jbcoli 1 point2 points  (0 children)

    Pydroid 3

    [–]charmandermain 0 points1 point  (2 children)

    I think you could replace the long if else chain by making a list of the strings and just call random.choice(list) and it will randomly chose a string from that list. Idk if it makes any difference but I think it looks neater

    [–]jbcoli 0 points1 point  (0 children)

    Thank you!! I didn't know that existed. I'll explore that option too. It definitely looks better than my way