#๐ im stuck on a question for homework
121 messages ยท Page 1 of 1 (latest)
@plain lagoon
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.
Hey mate what part dont you understand
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
Well you would need to start by prompting the user for a password and get to the validation later
password = input().len()
password = input("Enter a password: ")
I would do the len on a seperate line under a dif variable name like
plength = len(password)
that would overwrite the password input by the user so that you have it available to your program anymore
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
oh ok
well you dont need to do str(input()) because inputs are strings by defualt
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
as the code is using if and elif and else you should only get one of them
maybe exit() after an error so it only raises the first one it detects
ive change the 2nd one to elif
each if statement runts on its own
and it still gives me input 2 and 4 are wrong
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
so i only need if once
yes, in this instance when writing this code
but in other situations you will need more then one
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 ๐ฅฒ๐ฅฒ๐ฅฒ
if im trying to add a new one of these
what do i do
elif
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"
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
!= (is "not equals to")
that would be age "is less then or equal to" 8
i wrote that in the code but didnt say it right
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
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
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
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")
Hey @plain lagoon!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
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?
correct
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
Hey @plain lagoon!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
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 ๐
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
what is ord
is it that the first one can be used every time
and can always be used while this range test that you showed you can only be used for ranges of things
!d 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).
where did ord() come up, another exercise?
to check if its a special character
i need to do 2 if statements and an else statement
i think i would need to see the full question
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
i might just skip bc in an exam its only gonna be like 8 marks out of 100
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)
What even is this site?(I read most of the chats)
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.