Jump to content

Python Noob Questions (don't get mad I'm new)

So I'm learning python on the w3schools website between my part time jobs and there are some questions I have about certain things, for clarification. 

 

 

So I completed the syntax chapter on w3schools and codeacademy (im using both to better understand concepts from different perspectives). I was doing some fooling around and it was fun i have a question though. Why is this printing 2 texts? is it that i NEED another line?

 

# This code will cure covid-19 and save the world
"""
# I hope this works for multiline commenting, I'm not sure if it will but I really do hope it does. It could save the world! Why would a comment be this long anyways
"""
Atk = 10
Def = 50
HP = 100
Dmg = HP - (Atk - Def)
if Dmg < 1:
   print("Weakness... you have failed!")
if Dmg > 1 < 99:
  print("So you have worth...")     
if Dmg > 100:
   print("Nu- NUUUU~ haha I died NUUUUU~")  

 

Edited by Draxalite
Link to comment
Share on other sites

Link to post
Share on other sites

It's a programming language, you can do anything you want with it. The "marketing babble" is pointless.

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

So I completed the syntax chapter on w3schools and codeacademy (im using both to better understand concepts from different perspectives). I was doing some fooling around and it was fun i have a question though. Why is this printing 2 texts? is it that i NEED another line?

 

# This code will cure covid-19 and save the world
"""
# I hope this works for multiline commenting, I'm not sure if it will but I really do hope it does. It could save the world! Why would a comment be this long anyways
"""
Atk = 10
Def = 50
HP = 100
Dmg = HP - (Atk - Def)
if Dmg < 1:
   print("Weakness... you have failed!")
if Dmg > 1 < 99:
  print("So you have worth...")     
if Dmg > 100:
   print("Nu- NUUUU~ haha I died NUUUUU~")  

 

Link to comment
Share on other sites

Link to post
Share on other sites

(Please don't edit your post to completely change the meaning - it causes the previous posts not to have any context and make no sense. Instead, you can either post a new topic or just add a separate post with the new question (optionally editing the original one to mention that there's another question later or add a summary without removing the old content).)

 

The problem with your code looks like

if Dmg > 1 < 99:

Python does support range queries, but they aren't quite like that. Instead you need to reorder it, to be

if 1 < Dmg < 99:

 

What you had before is essentially equivalent to "Dmg > 1 and 1 < 99" rather than "Dmg > 1 and Dmg < 99" as you intended.

 

You probably also want to alter the bounds a bit - at the moment, it won't print anything for 1, 99 or 100.

 

A more standard way of writing this code would be

if Dmg < 1:
   print("Weakness... you have failed!")
elif Dmg < 100:
  print("So you have worth...")     
else:
   print("Nu- NUUUU~ haha I died NUUUUU~")  

That way you don't have to worry about getting the bounds to match correctly (elif means else if).

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Sakuriru said:

"Dmg > 1 < 99" should be "Dmg > 1 and Dmg < 99"

it worked! how many times can you put and in a line?

Link to comment
Share on other sites

Link to post
Share on other sites

As many as you want (aka until the whole thing is unreadable...)

F@H
Desktop: i9-13900K, ASUS Z790-E, 64GB DDR5-6000 CL36, RTX3080, 2TB MP600 Pro XT, 2TB SX8200Pro, 2x16TB Ironwolf RAID0, Corsair HX1200, Antec Vortex 360 AIO, Thermaltake Versa H25 TG, Samsung 4K curved 49" TV, 23" secondary, Mountain Everest Max

Mobile SFF rig: i9-9900K, Noctua NH-L9i, Asrock Z390 Phantom ITX-AC, 32GB, GTX1070, 2x1TB SX8200Pro RAID0, 2x5TB 2.5" HDD RAID0, Athena 500W Flex (Noctua fan), Custom 4.7l 3D printed case

 

Asus Zenbook UM325UA, Ryzen 7 5700u, 16GB, 1TB, OLED

 

GPD Win 2

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks for the help guys been really wonderful so far! I mentioned earlier that i was laerning from w3schools and codeacademy, well halfway through the introduction chapters codeacademy started asking me for a credit card. After some digging around i found out that i was on the pro course (the only course that teaches python 3 on that website) and the free version teaches python 2. What's the difference between python 2 and 3? Is there a good recommendation for another website i can learn python from for free?

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/27/2020 at 1:44 PM, Draxalite said:

Thanks for the help guys been really wonderful so far! I mentioned earlier that i was laerning from w3schools and codeacademy, well halfway through the introduction chapters codeacademy started asking me for a credit card. After some digging around i found out that i was on the pro course (the only course that teaches python 3 on that website) and the free version teaches python 2. What's the difference between python 2 and 3? Is there a good recommendation for another website i can learn python from for free?

Don't bother to learn Python 2. It's like a zombee who should have died a decade ago but is somehow still sticking around 😃 It has been officially retired in April this year, so, it won't get any updates from the Python foundation (which means that all newly-found and unpatched security holes will make it unusable pretty quickly). You may still encounter some legacy Python 2 code at your future workplace but, as long as you know Python 3, maintaining Python 2 code won't be too complicated.

 

The main differences are some syntax differences, usage of Unicode by default in Python 3 and other small differences (which are, however, big enough to break backwards compatibility).

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/27/2020 at 12:44 PM, Draxalite said:

Is there a good recommendation for another website i can learn python from for free?

Not so much a website to learn from but a really useful way to get valuable constructive criticism; Code review stack exchange. Another way to learn would be to pick up simple projects that "do something". I always found that creating things i enjoy or solving problems that i have keep me motivated to learn. Once you feel very comfortable writing simple scripts, gradually increase the scope and techniques involved. A quick search for simple python projects brought up this site. Which looks pretty good. You get a wide range of exposure.

 

Most importantly, have fun and don't take the learning process too seriously. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×