LEVEL UP Your Python Game!! #python #coding #programming

preview_player
Показать описание

Background Music:
Creative Commons / Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Рекомендации по теме
Комментарии
Автор

Every python tutorial: forget doing it yourself, here’s a library for you 😂

MichaelJWarrick
Автор

"Here's a nifty trick someone else made for you."

aion
Автор

This should've really been a for loop instead

for c, s in cycle(lights):
print(c)
time.sleep(s)

tragczny
Автор

while True:
for stage, timer in lights:
print(stage)
sleep(timer)

jayturner
Автор

Increase your build size just to write 1 line of code instead of 2

perstry
Автор

while True:
for light in lights:
print(light[0])
time.sleep(light[1])

lances
Автор

With that speed of the lights I'd be dead in a car crash

SalticHash
Автор

while True:
for a, b in lights:
print(a)
time.sleep(b)

ree
Автор

wouldn't that be simpler:

while True:
for light, duration in lights:
print(light)
time.sleep(duration)

aleksanderpanasiuk
Автор

Or just use a for loop instead of including another library lol

stikosek
Автор

this is pretty cool. i occasionally will use additional variables to a function as flags to control how the function functions. most people will just create another function, rightly so, instead of shoehorning 'flags' to a function to control how the function operates. (i do this occasionally when i have almost identical functions and want to cut down on duplicated code). now though this doesn't directly correlate to this, i can see in my mind a world of ideas now that i know this (thank you) as well as giving me more insight into just how flexible 'itertools' is. thanks again.

rljpdx
Автор

goddammit shorts and goddammit library tutorials

DeveloVooshGWeb
Автор

Mom says "while true" is a bad thing

micheleagnello
Автор

How does it stop, in a while loop, does it make it fault at the end of the code, to break while true?

sebastianlondono
Автор

without importing the library, just use generators with yield c, s for each one

hamzaomari
Автор

python users importing libraries to do literally one thing: "im so smart"
everyone else in literally every language in programming: "sir, have you tried the shift+5 key on your keyboard?" (hint: it makes a % symbol!!1!1!!111!1)

beanureeves
Автор

i love itertools. every function is so useful! that could have been just a nested while and for loop though.

YuraSuper
Автор

The issue is that you're cycling, opposite to how a traffic light works, it goes back and forth so something like this would be better for that purpose:

import time



lights = {"Green":2,
"Yellow":0.5,
"Red": 2}



lights2 = ["Green", "Yellow", "Red"]


i = 0
while True:
try:
print(lights2[i])

i += 1
except IndexError:
i -= 2
print(lights2[i])

i -= 1

aggi
Автор

from time import sleep
lights = [("Green", 2), ("Yellow", 0.5), ("Red", 2)]
i = 0
while True:
i = (i + 1) % 3
c, s = lights[i]
print(c)
sleep(s)

gamatek
Автор

Need to print something?



1. Import print from bing chilling

blueschnabeltier_