#๐Ÿ”’ code input no work if hi bye

210 messages ยท Page 1 of 1 (latest)

olive cape
#

123

tropic fossilBOT
#

@olive cape

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.

olive cape
#

@frosty oasis

#

if input ("hi"):
print("bye")

#

alr so

#

why didnt this work

frosty oasis
#

Start simpler:

olive cape
#

mmm

frosty oasis
#
my_message = input("Type something please")
print(my_message)
olive cape
#

thats simpler?

frosty oasis
#

Try it

ionic hamlet
#

ok so what do you suppose this line does: if input("hi"):

olive cape
olive cape
frosty oasis
ionic hamlet
#

have you actually read the documentation of input()?

#

something tells me you haven't even looked at it

olive cape
#

nd then it js

#

says

ionic hamlet
#

"pressed play"?

olive cape
#

"ap csp" in what i wrote in the ("123")

olive cape
wraith ledge
#

They ran the program ig

ionic hamlet
#

I don't know what you're referring to

olive cape
olive cape
wraith ledge
#

Prolly vsc

olive cape
#

ran the program

olive cape
#

yea

frosty oasis
olive cape
ionic hamlet
#

prints what

olive cape
#

i dont get it

frosty oasis
olive cape
#

bro i dont think u understand wat im saying

#

it legit

#

printed tihs

frosty oasis
olive cape
#

print("123")

#

simpler

ionic hamlet
#

depends on what you want to do

olive cape
ionic hamlet
#

how what

frosty oasis
ionic hamlet
#

speak in complete sentences please

olive cape
olive cape
frosty oasis
#

Input is a function that "returns" whatever the user typed.

olive cape
#

ty

#

but

#

i want to make it so

#

when i run the cmd

frosty oasis
#

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?

olive cape
#

i write like for exmaple "123" then itll re write to me "4321

#

or smt

ionic hamlet
#

ok, what's the logic then?

ionic hamlet
#

what if you type foo instead?

#

should it print "4foo"?

olive cape
#

whats foo

#

what

frosty oasis
ionic hamlet
#

I'm asking what the logic will be

ionic hamlet
#

you said that if you type 123 to the prompt it should print 4321

#

by what logic?

ionic hamlet
#

this doesn't prepend 4 to the string

olive cape
#

what does IF mean

#

what does if do

ionic hamlet
#

it runs the indented code block if the expression evaluates to true

olive cape
#

what happesn if no if

ionic hamlet
#

if there's no if, then there wouldn't be an indented code block following it either

olive cape
#

why this no work

olive cape
#

OH

#

OH

#

its

#

this space

#

behind print

#

right

ionic hamlet
#

indentation means spaces before the code line

olive cape
#

alr

#

else is

#

if anything else

#

alr im starting to like coding its nice

#

connecting the dots

ionic hamlet
#

!e

if True:
    print("This is always printed")
if False:
    print("This is never printed")
wraith ledge
#

I think you should learn some beginner course on python, it will be very easy.

olive cape
#

wai

ionic hamlet
#

!e

if True:
    print("This is always printed")
if False:
    print("This is never printed")
olive cape
#

why isnt this working

tropic fossilBOT
olive cape
#

!e print("123")

tropic fossilBOT
frosty oasis
olive cape
#

what

olive cape
tropic fossilBOT
#

Hey @olive cape!

Please edit your message to use a code block

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

This will result in the following:

print('Hello, world!')```
olive cape
#

i js copy pasted u

frosty oasis
ionic hamlet
#

where did you set the value for my_message?

frosty oasis
#

This code was supposed to come after the original "input" code

olive cape
#

oh

olive cape
#

if input ("hi"):
print("bye")

#

how do i

#

combine them8

ionic hamlet
#

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?

olive cape
#

no

frosty oasis
ionic hamlet
#

well that is what input() does

wraith ledge
#

You should store the value in a variable from input () and then use that variable to compare in if

frosty oasis
olive cape
#

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

olive cape
#

wait bro

#

bro

#

what do we call the guy who writes the codes and what do we clal the guy who runs cmd

#

user

olive cape
#

i thought my_message was js for what the user writes

frosty oasis
#

Let's talk about my_message = input("Type something please")

ionic hamlet
#

yes, that's where the user's input is stored

frosty oasis
#

The thing on the left, "my_message" is a variable. It stores whatever comes from the right side (of the =)

frosty oasis
olive cape
#

hmm i dont understand but alright

#

how is my message js a variable

wraith ledge
#

Variable name can be anything that follows a naming convention

olive cape
frosty oasis
olive cape
#

not js what user writes

frosty oasis
#

You could've written: "billy_bobby_is_awesome"

olive cape
#

how will the python know its a variable

frosty oasis
olive cape
#

oh

#

thats tuff

frosty oasis
#

abc = "My Name is Apple"

olive cape
#

so wait it could be

frosty oasis
#

That means the variable abc is the string "My Name is Apple"

olive cape
#

123 = input("456")

olive cape
#

!e
123 = input("456")

tropic fossilBOT
# olive cape !e 123 = input("456")

:x: Your 3.13 eval job has completed with return code 1.

001 |   File "/home/main.py", line 1
002 |     123 = input("456")
003 |     ^^^
004 | SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
frosty oasis
frosty oasis
olive cape
#

!e
zxc = input("456")

tropic fossilBOT
# olive cape !e zxc = input("456")

:x: Your 3.13 eval job has completed with return code 1.

001 | 456Traceback (most recent call last):
002 |   File "/home/main.py", line 1, in <module>
003 |     zxc = input("456")
004 | EOFError: EOF when reading a line
frosty oasis
#

The bot can't do input

olive cape
#

kk

#

wait so

#

with this

#

i can make a manual calculator

#

like

frosty oasis
#

Sure, a lot of students will do small projects like - a physics equation calculator.

olive cape
#

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

umbral atlas
frosty oasis
umbral atlas
# olive cape 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)

frosty oasis
#

(they're struggling with what functions are, and how to construct if statements, so I fear this may be premature)

frosty oasis
wraith ledge
frosty oasis
#

(i guess i mean the entire book)

olive cape
#

but i didnt memorize it so i needa keep looking back at

#

billy bobys msg

wraith ledge
#

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"))

frosty oasis
#

Once you understand it, and can make changes to it... then you'll be ready for calculator.

tropic fossilBOT
#
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.