[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Le newb here Since in Python "switch" doesn't

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 1

File: dank gaem.png (15KB, 419x534px) Image search: [Google]
dank gaem.png
15KB, 419x534px
Le newb here

Since in Python "switch" doesn't exist, what could i do to make this code less shit?

Thanks
>>
>>58323716
stupid fuckin faggot learn to use google

https://stackoverflow.com/questions/60208/replacements-for-switch-statement-in-python
>>
>>58323716
As dumb as it sounds, by not using Python.
Try Lua.
>>
>>58323716
>make python less shit
>>
Have you tried using a language that isn't full retard shit?
>>
>>58323768
I remember there were some downsides of Lua.
>>
>>58323716
dont use strings, use numbers
>>
>>58323716
A list, retard. Switch statements (in C and Java) only deal with a single variable, so you'll need to insert a conditional for usChoice too. I would probably use an enum for this purpose anyway.
>>
How about you just generate a random number between 1 and 3 (inclusive) and use that for the 3 possible outcomes of the game, instead of pretending that a users choice even matters and spending all those comparing strings
>>
>>58324149
The only useful advice in this thread
>>
You could try using a dictionary as a dispatch table.
>>
>>58324886
>>58324149
it would confuse the logic of the game to just straight up use numbers. easier to use a container and just reference that by index programmatically, like
import random
tools=("Rock","Paper","Scissor")
challenge=input("do the thing here: ").capitalize()
robot=random.choice(tools)

if challenge in tools:
if tools.index(challenge)==tools.index(robot):
print("tie; you chose {} and so did the damned robot".format(challenge))
elif tools.index(robot)==tools[tools.index(challenge)-1]:
print("you won! holy shit! the robot picked {} but you cunningly chose {}".format(robot, challenge))
else:
print("you lost, fucking loser. you picked {} and the robot picked {}".format(challenge,robot))
>>
>using strings when the strings are already in an array

Nigga, you dumb.
>>
>>58323716
holy shit nigger if you know a language like C/++ or Java and this is the best shit you could come up with in Pytoddler you should just give up now
>>
but switch IS a bunch of elifs, anon
>>
> array ["player wins", "pc wins", "tie"]
> get user input
> ignore it and generate a random array index and print it
Done
>>
>>58325203
this actually. forget about my post >>58325024
Thread posts: 17
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.