#๐Ÿ”’ im stuck on a question for homework

121 messages ยท Page 1 of 1 (latest)

plain lagoon
toxic estuaryBOT
#

@plain lagoon

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.

golden mountain
#

Hey mate what part dont you understand

plain lagoon
#

idk how to start iut

#

i havent done this for like a week

#

and its a learning thing i know how to do the if statements

#

but not the len and the .lower

golden mountain
#

Well you would need to start by prompting the user for a password and get to the validation later

plain lagoon
#

password = input().len()

golden mountain
#

password = input("Enter a password: ")

plain lagoon
#

password = len(password)

#

where does the len bit go

golden mountain
#

I would do the len on a seperate line under a dif variable name like
plength = len(password)

undone niche
golden mountain
#

^

#

Then you would have an interger and not the original string password

plain lagoon
#

password =input()
if len(password() < 8:
print("password too short")
elif password.lower() == password
print("password needs uppercase letter")
else:
print("password valid")

#

thats how my teachers say to do it

#

because on this site u dont need to ask for an input

#

it just gives u one

golden mountain
#

oh ok

#

well you dont need to do str(input()) because inputs are strings by defualt

plain lagoon
#

password =input()
if len(password) < 8:
print("password too short")
elif password.lower() == password:
print("password needs uppercase letter")
else:
print("password valid")

#

would this work

#

it says password too short and password needs an uppercase letter

#

how do i make it only say

#

1

golden mountain
#

why does it matter if it says both

#

if they are both true

plain lagoon
#

idk

#

this website is aids

#

and it wants only 1

undone niche
#

as the code is using if and elif and else you should only get one of them

golden mountain
#

maybe exit() after an error so it only raises the first one it detects

undone niche
#

oh, there is the problem

#

your using two if statements

plain lagoon
#

ive change the 2nd one to elif

undone niche
#

each if statement runts on its own

plain lagoon
#

and it still gives me input 2 and 4 are wrong

undone niche
#

if and else runs together

#

just like if and elif also runs together

#

and so does if, elif and else

#

you will just get the first one that is true, then it skips the rest of them

#

but when you use a new if you can see it as if you are creating a new group of conditionals

plain lagoon
#

so i only need if once

undone niche
#

yes, in this instance when writing this code

#

but in other situations you will need more then one

plain lagoon
#

this website is aids

#

it didnt let me get 2 and 4 because

#

i didnt put a space before the

#

password needs an uppercase letter

#

but i didnt think that mattered

#

ive got it now thank you for helping

#

i have to do 34 more questions now ๐Ÿฅฒ๐Ÿฅฒ๐Ÿฅฒ

plain lagoon
#

what do i do

#

elif

undone niche
#

and it has to go after an if

#

all conditional "groups" are required to start with an if and can optionally have an else as the last part of the "group"

plain lagoon
#

how do i say if its not equal to

#

elif password.lower() = password

undone niche
#

you can have more or less as many elif statements in between as you like, it just gets ridicules at some point and then there is probably better ways to go about solving it

undone niche
plain lagoon
#

is age <= 8

#

equal or greater than 8?

undone niche
plain lagoon
#

i wrote that in the code but didnt say it right

undone niche
#

i mean, that is what you get when you use <=

#

if you want "greater then or equal to" something on the right hand side you need to use >= instead

plain lagoon
#

how do i make a limit for it to be greater than

#

because i need it to be greater than or equal to 12

#

but i also need a greater than or equal to 18

#

but it just gives me the 12 one every time

undone niche
#

what do you mean with limit and what does 12 and 18 even mean here?

#

i have no context of what you are working with right now, so it's really hard to understand what you are talking about

plain lagoon
#

age = input()
age = int(age)
if age < 3:
print("You don't have to go to School")
elif age >= 3:
print("You should be in Primary School")
elif age <= 12:
print("You should be in either Primary or Secondary")
elif age >= 13:
print("You should be in Secondary School")

toxic estuaryBOT
#

Hey @plain lagoon!

Please edit your message to use a code block

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

This will result in the following:

print('Hello, world!')```
undone niche
#

oh, i get it

#

a group of conditionals will always just run the block of code that matches first and skip all other conditional tests and blocks in the "group"

#

so the first one will be true for all ages less then 3, even negative ones ๐Ÿ˜€

#

and the second one will be true for all that is equals to or larger then 3, which means it will match all other ages and no other tests will be checked

#

you either have to arrange the tests in an order so that those most specific ones or those that has precedence go first
or you have to add more conditions to the problematic ones

#

@plain lagoon have you learned about the and keyword when working with booleans yet?

plain lagoon
#

no

#

i know the gates

#

with and needs both

#

or needs 1

#

not is opposite

undone niche
#

correct

plain lagoon
#

age

age = input()
age = int(age)
if age < 3:
print("You don't have to go to School")
elif age >= 3 and age <= 11:
print("You should be in Primary School")
elif age <= 12:
print("You should be in either Primary or Secondary")
elif age >= 13:
print("You should be in Secondary School")
elif age <= 18:
pr

toxic estuaryBOT
#

Hey @plain lagoon!

Please edit your message to use a code block

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

This will result in the following:

print('Hello, world!')```
undone niche
#

yeah, that second one should work, or you can reuse the number 12 again by staing

elif age >= 3 and age < 12:
```this isn't as important when working with integers (whole numbers) but it will be much more important when you start working with decimal numbers, then it's a big difference between the two
#

there is also a slightly more advanced way of giving an acceptable range that some people think is harder to read and understand

elif 3 <= age < 12:
#

then you test for both the lower and upper limits more or less at the same time

#

@plain lagoon ๐Ÿ‘†

plain lagoon
#

im gonna try that one bc imo shorter is simpler

#

bc i can remember it more easily

undone niche
#

and when needing to repeat several ranges i think it's more readable

#

and you end with the same number as you start the next conditional with if you are going to have a continues range of conditionals

#

but it's still helpful to know both ways, since this can only be used for some kind of tests

#

say for example that you have to test for age and height, then you need to go with and between those two tests

plain lagoon
#

what is ord

plain lagoon
undone niche
undone niche
toxic estuaryBOT
#
ord

ord(c)```
Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. For example, `ord('a')` returns the integer `97` and `ord('โ‚ฌ')` (Euro sign) returns `8364`. This is the inverse of [`chr()`](https://docs.python.org/3/library/functions.html#chr).
undone niche
#

where did ord() come up, another exercise?

plain lagoon
#

to check if its a special character

#

i need to do 2 if statements and an else statement

undone niche
#

i think i would need to see the full question

plain lagoon
undone niche
#

at the end there it more or less literally tells you how to do it
and since this is working with ranges, once again the range test from above would work instead of using and, but this time it's inclusive ranges on both sides, so you would need to use the "or equals" versions on both sides

plain lagoon
#

i might just skip bc in an exam its only gonna be like 8 marks out of 100

undone niche
#

so this can also be solved without using and and just using something like 65 <= ord(character) <= 90 for the stated example at the end of the text and would be 65 to 90 (inclusive, this time around)

#

exams can be stupid, sometimes they want you to solve something in one particular way and not giving you leeway to solve in any correct way, even if it might be "better" (depending on what is prioritized)

naive violet
#

What even is this site?(I read most of the chats)

toxic estuaryBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.