#๐ I get really confused over for loops
95 messages ยท Page 1 of 1 (latest)
@tall aurora
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.
what's the confusion about?
have you tried writing trivial code that uses a for loop?
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?
You wouldn't really use loops in your example here. Not everything needs to be a loop.
Loops are useful when you need to repeat a block of code and have it apply to multiple elements contained in an iterable
https://www.w3schools.com/python/python_while_loops.asp
try this
yeah i wasnt saying that it did, its just the guy talk about trivial code so I asked if that is trivial code.
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
trivial code means just work with some very basic data as an example. Once you understand it with a basic example, you can expand on your knowledge to work with something more complex
oh okay
trivial code?
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
wow
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
will do, thanks!
also how do I make it so my code looks like that on discord?
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
yeah... i jsut dk where else to get help from
you're also not going to train your brain on how to think like a programmer
read this embed
thats what happend with that shortctu app code ๐
o
print('Hello world!')
o i see
cheers
haha yes
Also unrelated question, are you working on Combo Devils?
Cuz I was wondering what programming language it uses
Hey sorry I was away. I do work on it, yes!
It uses Unity and C#, but I don't really work on the gameplay/game engine side of things
cool, dosnt unity cost like .20p per um download?
it depends
?
how come
also I want to learn C# funny that. but I feel I should learn python first before C# to make it easier?????
there's different pricing models and unity will choose the lesser depending on how much profit is made in a specific time frame
ye
@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
What have you tried so far?
erm
im not skilled
uppercase
My python ig guess you could call it vocabulary is very um... small
Do you know how to make a string into uppercase?
no
!e
word = 'hello'
print(word.upper())
:white_check_mark: Your 3.12 eval job has completed with return code 0.
HELLO
It can be done with the .upper() method
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()
I tryed putting it infront of those two places
Oh
I only put .upper
๐ Sorry
i forgot the ()
.upper and .upper() are very different ๐
it's the name of the method, so it would be the instructions contained within
!e
print(str.upper)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
<method 'upper' of 'str' objects>
it's very unlikely to matter for a beginner
okay!
I'm on 3.7
๐
(and am not a beginner)
oh ok
I can tell
๐
Okay ill try the other two. Do you want me to let you know how I get on or should I not bother you?
You can reply if this thread is still open. I do need to get going very soon though
alr!
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.