#๐Ÿ”’ PYTHON FOR BEGINNERS

87 messages ยท Page 1 of 1 (latest)

stable marsh
#

need help with these excercises for practice

burnt hollyBOT
#

@stable marsh

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.

stable marsh
#

i have no idea how to start all of those three

finite moat
#
  1. tells you each step in order
  • take input from user
  • is even?
    • print event
  • is odd?
    • print odd
stable marsh
#

can python automatically identify if an integer is odd/even?

worthy beacon
#

Yes

stable marsh
#

oh

worthy beacon
#

Use the % operator

stable marsh
#

to what

worthy beacon
#

Like this

#

4 % 2 = 0

#

So it's even

#

5 % 2 = 1
So it's odd

stable marsh
#

i mean how

#

or like where

worthy beacon
#

Okay so you input a number

stable marsh
#

whered u get those numbers

worthy beacon
#

I mean assign a number to a variable

stable marsh
#

done

worthy beacon
#

What's your variable

stable marsh
#

n

#

the user input

worthy beacon
#

So n = int(input("Enter number "))

stable marsh
#
n = int(input("Enter a value: "))
#

yes

worthy beacon
#

So then you use conditional statements

#

If n % 2 == 0:
print('The number is even')

stable marsh
#

what does the n % 2 == 0 mean

worthy beacon
#

Basically it means if n divided by 2 has 0 as a remainder

stable marsh
#

ohh

#

okay i get ir

worthy beacon
#

And then use an else statement for if the number is odd

stable marsh
#

ive finished it

#
n = int(input("Enter a value: "))

if n % 2 ==0:
    print("The value is even")
else:
    print("The value is odd")
    
print("Thank You")```
#

thanm you!!

#

now for item 2

#

still dk how to starf

finite moat
#

"that asks for their exam score"

#

that's where you start ๐Ÿ™‚

stable marsh
#

yeah i meant after that

finite moat
#

ok what do you think needs to be done then?

stable marsh
#

i dont know..

#

idk what to tell python what to do in order for me to execute the given problem

finite moat
#

break it down into small steps

#

so what's the overall goal for this one?

stable marsh
#

i was thinking earlier to assign a list of values to a variable, like A = 90 to 100 but idk how to do that and im sure there's an easier way than making a list manually

finite moat
#

ok i see. You could do that, but then it makes it so you basically have to type out every number from 0 to 100

#

you don't want that right

stable marsh
#

yes

#

do we use inequalities?

finite moat
#

yes

stable marsh
#

uhh how?

#

idk how to make it like n >= 90 but stops at 100

finite moat
#

so there are two conditions then

#

must be >= 90 but also <= 100

stable marsh
#

ohh

#

how do i write that in py

#

with the condition

finite moat
#

do you know what and, or, and not do?

stable marsh
#

no

finite moat
#

these are called boolean operators

#

however, there's a way to do this without needed them

#

you can do (psuedo code)

  • if grade is >= 90
    • A
  • otherwise, if grade is >= 80
    • B
  • otherwise, if grade is >= 70
    • C

etc.

stable marsh
#

can you make an example writing that in py?

finite moat
#

no because then i'd just be giving you the answer

#

you'll want to use if and elif and else

stable marsh
#

oh right

#

what if the user types something > 100

#

is otherwise a primitive code?

finite moat
#

Well what does the question say about that?

stable marsh
#

oh, u just used it as a word to not give the answer?

#

okay what

#

currently 1am im just trying my best to stay awake

stable marsh
#

okay i did it

#

now i just wanna know how to tell my code anything >100 is an invalid input

#

nvm

#

just done it too

finite moat
#

Nice

stable marsh
#
n = float(input("Enter your grade: "))

if n > 100:
    print("invalid")
elif n >= 90:
    print("A")
elif n >= 80:
    print("B")
elif n >= 70:
    print("C")
elif n >= 60:
    print("D")
else:
    print("FAILED")```
finite moat
#

you don't need me ๐Ÿ˜„

stable marsh
#

thank you!!

stable marsh
finite moat
#

no prob

burnt hollyBOT
#
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.