+ 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

23rd Jul 2018, 4:12 PM
LONGTIE👔
LONGTIE👔 - avatar
23 Réponses
+ 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:
23rd Jul 2018, 5:36 PM
HonFu
HonFu - avatar
+ 11
Ok Thanks !
23rd Jul 2018, 6:14 PM
ᏳoƊoԲᎮc !
ᏳoƊoԲᎮc ! - avatar
+ 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?
23rd Jul 2018, 6:07 PM
ᏳoƊoԲᎮc !
ᏳoƊoԲᎮc ! - avatar
+ 6
HonFu thanks it works now
23rd Jul 2018, 5:44 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 5
HonFu what did you input?
23rd Jul 2018, 4:42 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 5
HonFu I was inputting jq
23rd Jul 2018, 4:44 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 4
Works for me. What do you want the output to be?
23rd Jul 2018, 4:35 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Kuba Siekierzyński i want the out put to be hi
23rd Jul 2018, 4:36 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 4
I want it to be if I input a item in the list and q it will output hi
23rd Jul 2018, 4:46 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 4
HonFu what is the slash for?
23rd Jul 2018, 5:38 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 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
23rd Jul 2018, 6:09 PM
HonFu
HonFu - avatar
+ 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.
23rd Jul 2018, 4:58 PM
HonFu
HonFu - avatar
+ 3
Yeah, but you wrote more, which means you thought quicker. :-D (tbh, I actually did print it.)
23rd Jul 2018, 5:03 PM
HonFu
HonFu - avatar
+ 3
Sounds like a case for detective RegEx. ;-)
23rd Jul 2018, 5:21 PM
HonFu
HonFu - avatar
+ 2
I tried it too - seems to work!
23rd Jul 2018, 4:41 PM
HonFu
HonFu - avatar
+ 2
jq is not in your list.
23rd Jul 2018, 4:45 PM
HonFu
HonFu - avatar
+ 2
Hm... tricky. ^^
23rd Jul 2018, 4:50 PM
HonFu
HonFu - avatar
+ 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!
23rd Jul 2018, 4:58 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Hi HonFu! We pretty much wrote the same thing 😁
23rd Jul 2018, 5:02 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 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?
23rd Jul 2018, 5:18 PM
Kishalaya Saha
Kishalaya Saha - avatar