Day 032 - Project 32 : Greetings in Different Languages

If you have any questions, comments or issues with this project please post them here!

1 Like

Built a random greetings list to greet you in different languages :wave:.

https://replit.com/@JackAdem/Day-032-Project-32-Greetings-in-Different-Languages?v=1

Day 32 of #Replit100DaysOfCode #100DaysOfCode.

1 Like

Question:
Guess it might be pretty simple when you know. But have struggled for an hour now :confused:

I can’t make the code break when the input is exit. I know the first steps could be more smooth looking at the solution. But looks like it’s the comparison or while True loop, where i do something wrong.

Thanks :slight_smile:

import random, os, time

greeting = ["Hej", "Hallo", "Goddag", "Gutentag", "Davs", "Hejsan", "Tjenna", "Ciao"]


def randhilsen():
    tilf = random.randint(0, 7)
    return tilf


while True:
    signoget = input("Sig noget: ")
    if signoget != "Exit":
        supertilf = randhilsen()
        hilsen = greeting[supertilf]
        print(
            f"""Man kan sige hej på mange måder eksempelvis 
    {hilsen}"""
        )
        time.sleep(5)
        os.system("clear")
    else:
        break

Please format the code (copy it where the text code snippet is).
Without solving the error i can say that in python Exit and exit are not the same thing :slight_smile:

import random, os, time
greeting=[“Hej”, “Hallo”, “Goddag”, “Gutentag”, “Davs”, “Hejsan”, “Tjenna”, “Ciao” ]

def randhilsen():
tilf=(random.randint(0,7))
return tilf

while True:
signoget = input(“Sig noget: “)
if signoget !=“Exit”:
supertilf= randhilsen()
hilsen=(greeting[supertilf])
print(f””“Man kan sige hej på mange måder eksempelvis
{hilsen}”“”)
time.sleep(5)
os.system(“clear”)
else:
break

Ahr… Doesn’t look correct. Not sure how I edit and/or ad it afterwards

Almost, and I forgot to say welcome as this is your first post. Sorry

Click on the pencil symbol and put the code between the symbols :-)

Thanks :slight_smile:

By the way “Exit” wasn’t meant as an command but just a way to get out could be other words.

I know. I meant that if you type Exit as command in “your program when running” or exit, for python those are two different commands, except when you check for both or force the text to be always lower or upper case before you do an IF …

you need to do something like:

a = input("command: ")
if a.lower() == "exit":
    ...

I hope this helps without telling even more :slight_smile:

3 Likes

I’ll give it a look later today :slight_smile:

But still can’t find the pensil :confused: Maybe because I don’t have all rights since im new :thinking:

It could be … i guess somebody more powerful then me in the forum will jump in and fix it later on. Let me know if my post helped, if so mark it as solution (this will close the thread )

The reason why you can’t exit it maybe is because that you typed “exit” instead of “Exit”, maybe try typing the input exactly equal to the compared string, in this case is “Exit” but not “EXIT” or “exit”

Hi @BoringPanda, and welcome to the Replit Ask community!
Looking at your plaintext code (and assuming all indentation is right), it seems that everything is okay. The only reason I can think it wouldn’t work is because when you’re prompted with "Sig noget: ", you put something not equal to “Exit”. (see @whileTRUEpass’ answer)
A simple miscapitalization like “exit” or “EXit” can result in this problem.

In further posts, please use codeblocks! You can use them like so:
``` three backticks
then another three to close the codeblock.

like so!

Cheers! :smiley:

1 Like

Thanks for all the answers and help! Not 100% sure what change made the difference. Might be a night sleep. Might just be the typo of capital even though I thought I did it yesterday :slight_smile:

But now it works :slight_smile:

So looking at the Answer for the challenge, and the code is:

import random
greetings = ["Hello there!", "Konnichiwa", "Guten Tag!", "Bore Da!"]
index = random.randint(0,3)
print(greetings[index])


                              
</details>

And I feel the </details> tag is incorrect as there is no “inclination” of HTML in the code, and the actual code does not work whatsoever, it only prints Hello There!

Please correct any of my errors.

1 Like

@ShaunMostert all you need is this. It works just fine the </details> doesn’t need to be there like you said though. Since there isn’t any HTML. It just prints a random greeting from greetings from the random.

import random
greetings = ["Hello there!", "Konnichiwa", "Guten Tag!", "Bore Da!"]
index = random.randint(0,3)
print(greetings[index])
2 Likes

Much appreciated, thought the HTML details tag was confusing :rofl:

@ShaunMostert yeah I don’t know why it would be there, since you said it only printed “Hello there!” that might have made that happen :person_shrugging:.

1 Like

I think the details tag was there because there was a problem formatting the tutorial. @DavidAtReplit?

Oh I’ll take a look in the morning and see what’s up!

2 Likes