#๐ code input no work if hi bye
210 messages ยท Page 1 of 1 (latest)
@olive cape
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.
Start simpler:
mmm
my_message = input("Type something please")
print(my_message)
thats simpler?
Try it
ok so what do you suppose this line does: if input("hi"):
when i press play, i expect it to give me the option to write smth, i write hi and then it says bye
i did and im confused
Ok, what are you confused about?
have you actually read the documentation of input()?
something tells me you haven't even looked at it
i wrote it and pressed play
nd then it js
says
"pressed play"?
"ap csp" in what i wrote in the ("123")
idk what its called bro im new
They ran the program ig
I don't know what you're referring to
no i dont know this im watching a vid and testing this out
ues
Prolly vsc
ran the program
You're good. So waht are you confused about?
it js prints it
prints what
i dont get it
Yes, now read the code I gave you
Yup, whatever you type, it'll print.
after i copy paste
depends on what you want to do
how
how what
I'm trying to show you how "input" works.
speak in complete sentences please
oh
how does it depend on what i want to do
Input is a function that "returns" whatever the user typed.
mmmm ok i understand that
ty
but
i want to make it so
when i run the cmd
my_message = input("Type something") will take whatever you typed and store it in "my_message"
Now, you want an "if" statement to check if my_message is "Hi", right?
ok, what's the logic then?
yea sure
makes sense
if my_message == "Hi":
print("Hi to you too")
else:
print("Why u no say hi?")
I'm asking what the logic will be
OH YEAH THIS
tysm bro
this logic
this doesn't prepend 4 to the string
rq so my_message simply means ur giving the user the oppurtinty to write smt
what does IF mean
what does if do
it runs the indented code block if the expression evaluates to true
what happesn if no if
if there's no if, then there wouldn't be an indented code block following it either
i copy pasted exactly this
whats an indented code block
OH
OH
its
this space
behind print
right
indentation means spaces before the code line
so the space behind print
alr
else is
if anything else
alr im starting to like coding its nice
connecting the dots
!e
if True:
print("This is always printed")
if False:
print("This is never printed")
I think you should learn some beginner course on python, it will be very easy.
!e
if True:
print("This is always printed")
if False:
print("This is never printed")
why isnt this working
:white_check_mark: Your 3.13 eval job has completed with return code 0.
This is always printed
!e print("123")
:white_check_mark: Your 3.13 eval job has completed with return code 0.
123
whats true faulse
Show the whole code
what
if my_message == "Hi":
print("Hi to you too")
else:
print("Why u no say hi?")
Hey @olive cape!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
i js copy pasted u
Yah, but what happened to the input?
where did you set the value for my_message?
This code was supposed to come after the original "input" code
this code
how do you what
input("hi") prints a prompt with the message "hi" and then awaits user input
is that what you wanted to do?
no
Combine my two code blocks: #1410243182981021787 message and #1410243182981021787 message
well that is what input() does
how do i make it work then
You should store the value in a variable from input () and then use that variable to compare in if
put them in the same file and run it
my_message = input("Type something please")
print(my_message)
if my_message == "Hi":
print("Hi to you too")
else:
print("Why u no say hi?")
OH
oh yeah it works
wait so
wait bro
bro
what do we call the guy who writes the codes and what do we clal the guy who runs cmd
user
The programmer and user?
ok ok
i thought my_message was js for what the user writes
Let's talk about my_message = input("Type something please")
yes this
yes, that's where the user's input is stored
The thing on the left, "my_message" is a variable. It stores whatever comes from the right side (of the =)
whats a variable...
x y z?
It's just a label for some data. Like x,y,z in math... or "my_message"
Variable name can be anything that follows a naming convention
so wait my message does 2 stuff
"my_message" is just a name for whatever you typed.
not js what user writes
You could've written: "billy_bobby_is_awesome"
how will the python know its a variable
Because it's on the left side of an equals sign
abc = "My Name is Apple"
so wait it could be
That means the variable abc is the string "My Name is Apple"
123 = input("456")
:x: Your 3.13 eval job has completed with return code 1.
001 | File [35m"/home/main.py"[0m, line [35m1[0m
002 | [1;31m123[0m = input("456")
003 | [1;31m^^^[0m
004 | [1;35mSyntaxError[0m: [35mcannot assign to literal here. Maybe you meant '==' instead of '='?[0m
There's some rules with variable names... like, they can't be numbers.
zxc
that'd work
!e
zxc = input("456")
:x: Your 3.13 eval job has completed with return code 1.
001 | 456Traceback (most recent call last):
002 | File [35m"/home/main.py"[0m, line [35m1[0m, in [35m<module>[0m
003 | zxc = input("456")
004 | [1;35mEOFError[0m: [35mEOF when reading a line[0m
The bot can't do input
Sure, a lot of students will do small projects like - a physics equation calculator.
s = input("write here MAX NUMBERS UP TO 10: ")
print(s)
if s == "5+2"
print("7")
i can spam this but
waoit
then it can mbe
9+9
itll print 18
5+4 9
or is there an easier way
what I've seen most do is they ask for the first num, then the operator, and then the second num, and you perform something based on that.
There is an easier way, but you first need to get a little stronger at the basics.
alrigh
what
you take 3 inputs: one for a number, one for the type of operation (add, sub, etc), and one for another number, and then you do an operation based on the type the user asked for (you would do this with an if which is what you're tackling now I think)
Can I see an example
(they're struggling with what functions are, and how to construct if statements, so I fear this may be premature)
Bro whta
Try reading these examples first and make sure they make sense: https://python.swaroopch.com/io.html
If you have understood clearly wht u learned now, you can do it by yourself with just that, think about it.
Sorry, I meant this link: https://python.swaroopch.com/functions.html
(i guess i mean the entire book)
alr wait ill try
but i didnt memorize it so i needa keep looking back at
billy bobys msg
one thing I will say is that if you want to take a integer (number) as input then you gotta use int(input("enter the number"))
Yup, what I'm really saying is - experiment with what I gave you.
Once you understand it, and can make changes to it... then you'll be ready for calculator.
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.