+ 6
[SOLVED] Can f strings be used in elif statements?
https://code.sololearn.com/cQV1utVXEdiV/?ref=app why is this not working I need this to output hi when I input a item it test and q. like this jq
23 Respostas
+ 5
Okay, it really looks like if you go on looking for answers, you will just re-invent the re-wheel.
If we try anyway, how about playing with something like:
if any (x in az for x in test) \
and 'q' in az:
+ 11
Ok Thanks !
+ 10
HonFu Can u explain more about the slash pls can i use it without indenting? Are there more things like that to connect conditions?
+ 6
HonFu thanks it works now
+ 5
HonFu what did you input?
+ 5
HonFu I was inputting
jq
+ 4
Works for me. What do you want the output to be?
+ 4
Kuba Siekierzyński i want the out put to be hi
+ 4
I want it to be if I input a item in the list and q it will output hi
+ 4
HonFu what is the slash for?
+ 4
If a line gets too long and you want to increase readability, you can move part of your line to the next, using the escape-slash.
By this, the 'enter' at the end of the line gets ignored and the two lines get read as one.
If there are () , you don't even need that.
I make use of these things in my (only) code example:
https://code.sololearn.com/cLLY1586Ee35/?ref=app
+ 3
Okay, what your in-condition prints out to is:
"('k', 'h', 'j')%"
So if you enter the single letters, they are in this string, if you enter 'kq', it isn't.
+ 3
Yeah, but you wrote more, which means you thought quicker. :-D
(tbh, I actually did print it.)
+ 3
Sounds like a case for detective RegEx. ;-)
+ 2
I tried it too - seems to work!
+ 2
jq is not in your list.
+ 2
Hm... tricky. ^^
+ 2
If you do print(f"{test}q"), the output is, unsurprisingly,
('k', 'h', 'j')q
So if az is any ONE of those characters in the string above (except q, which is handled before), it would print hi. Yes, not just k, h, and j, even ( and , works!
+ 2
Hi HonFu! We pretty much wrote the same thing 😁
+ 2
I know you did, HonFu :) I never meant otherwise.
Anyway, is there a "nice" way to do what LONGTIE FOX wants? That is, printing "hi" for the input "jq" without changing the code much?