#๐Ÿ”’ I get really confused over for loops

95 messages ยท Page 1 of 1 (latest)

tardy belfryBOT
#

@tall aurora

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lost rivet
#

what's the confusion about?

#

have you tried writing trivial code that uses a for loop?

tall aurora
#

uh nope

#

wait is that where you write questions with a tone of if and else statements?

#

For e.g

print("Whats the day today")
answer = input()
day = "Monday"
if answer == day:
print("Well done thats right!")
else:
print("That was wrong it was Monday!!")

#

because I havent used loops in them

#

How would I structure that?

fierce wraith
#

Loops are useful when you need to repeat a block of code and have it apply to multiple elements contained in an iterable

ashen lagoon
#

https://www.w3schools.com/python/python_while_loops.asp
try this

tall aurora
#

So I have been working on this but I got help from uhh Ai for the for loops

import webbrowser

List of URLS

urls = {
"Youtube": "https://www.youtube.com/",
"Ebay": "https://www.ebay.co.uk/",
"ChatGPT": "https://chat.openai.com/"
}
print("Hello, welcome to the shortcut app!\n")
print("Before we start, would you like to add a custom link?")

custom = input("Yes or no: \n")

if custom.lower() == "yes":
custom_name = input("Enter the name you would like us to refer to the site as: ")
custom_url = input("Enter the URL of the site: ")
urls[custom_name] = custom_url
print(f"DayCustom link {custom_name} added.\n")

else:
print("Okay!")

Ask the user what link they want to open?

print("Choose from the following options: -")
for url in urls.keys():
print(f"\t {url}")

choice = input("Enter your choice: ")
print(f"you have chosen: {choice}")

if choice.lower() == "all":
for url in urls.values():
webbrowser.open(url)
else:
keyFound = False
for urlKey in urls.keys():
if choice.lower() == urlKey.lower():
print(f"opening url [{urls.get(urlKey)}]")
webbrowser.open(urls.get(urlKey))
keyFound = True
print(f"Opening choice: {choice}")

if not keyFound:
    print(f"Could not find option [{choice}] ")

how do the for loops work

fierce wraith
fierce wraith
#
shopping = ['milk', 'bread', 'eggs', 'mangoes']
#

use this to work with as an example

#

write some practice loops using this data

#

make a loop that prints out all the items in uppercase

#

make a loop that only prints out the items that start with m

tall aurora
#

wow

fierce wraith
#

make a loop that only prints out words with 2 or more vowels

#

etc

#

if you can do these basic exercises, then you can start to work with more and more complex code

tall aurora
#

will do, thanks!

tall aurora
fierce wraith
#

I also highly recommend staying away from AI/chatGPT code

#

especially as a beginner

#

it's going to write terrible code

#

and that code often won't work and you won't know enough to fix it

tall aurora
fierce wraith
#

you're also not going to train your brain on how to think like a programmer

fierce wraith
tardy belfryBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

tall aurora
#

o

#
print('Hello world!')
#

o i see

#

cheers

fierce wraith
#

np!

#

feel free to ask (humans) other questions if you feel stuck

tall aurora
#

Also unrelated question, are you working on Combo Devils?

#

Cuz I was wondering what programming language it uses

fierce wraith
#

It uses Unity and C#, but I don't really work on the gameplay/game engine side of things

tall aurora
fierce wraith
tall aurora
#

?

#

how come

#

also I want to learn C# funny that. but I feel I should learn python first before C# to make it easier?????

fierce wraith
#

there's different pricing models and unity will choose the lesser depending on how much profit is made in a specific time frame

tall aurora
#

@fierce wraith sorry to ping you but I have no idea how to do any of the things you said. uh are there any websites I can learn how to do it from?

u told me to do this

make a loop that only prints out the items that start with m
make a loop that only prints out words with 2 or more vowels
make a loop that prints out all the items in uppercase

tall aurora
#

erm

#

im not skilled

#

uppercase

#

My python ig guess you could call it vocabulary is very um... small

fierce wraith
fierce wraith
#

!e

word = 'hello'
print(word.upper())
tardy belfryBOT
fierce wraith
#

It can be done with the .upper() method

tall aurora
#

oh yeah I googled that

#

where do i put it

fierce wraith
#

well right now you're printing x to display the items in the list

#

so if you want them to be upper, you would print x.upper()

tall aurora
#

I tryed putting it infront of those two places

#

Oh

#

I only put .upper

#

๐Ÿ˜… Sorry

#

i forgot the ()

fierce wraith
#

.upper and .upper() are very different ๐Ÿ™‚

tall aurora
#

thanks so much

#

does .upper even do anything?

fierce wraith
#

it's the name of the method, so it would be the instructions contained within

#

!e

print(str.upper)
tardy belfryBOT
tall aurora
#

also i am still on uh python 3.10

#

should I update that?

fierce wraith
#

it's very unlikely to matter for a beginner

tall aurora
#

okay!

fierce wraith
#

I'm on 3.7

tall aurora
#

๐Ÿ’€

fierce wraith
#

(and am not a beginner)

tall aurora
#

oh ok

tall aurora
#

๐Ÿ˜…

#

Okay ill try the other two. Do you want me to let you know how I get on or should I not bother you?

fierce wraith
#

You can reply if this thread is still open. I do need to get going very soon though

tardy belfryBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.