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 .

Day 32 of #Replit100DaysOfCode #100DaysOfCode.

1 Like

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

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

``````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

``````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

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

3 Likes

Iâ€™ll give it a look later today

But still canâ€™t find the pensil Maybe because I donâ€™t have all rights since im new

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!

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

But now it works

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

@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 .

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