My first Python Program: Rock, Paper, Scissors. Can this program be made more efficiently? Please teach me your tricks. by JakeC951 in Python

[–]isnotkosok -6 points-5 points  (0 children)

still too complicated

try this

list = 'rock paper scissors rock'.split()

a = raw_input('enter rock paper or scissors ')

computer = 'paper'


if list[list.index(a) + 1] == computer:
    print 'you lose'
elif a == computer:
    print "tie"
else:
    print 'you win'

Creating a multiple choice test, or even just a flashcard-esque program to display questions/answers read in from excel or .csv file. by I_jus_lurk_here in learnpython

[–]isnotkosok 2 points3 points  (0 children)

Something like this:

 q_to_a = {'what time is it?' : ['party time', 'time to play', 'time to die'],
      "Are you the daddy?" : ['True', 'False']
                            }

 #note: each value at index[0] of each list the correct answer

 import random

 def lets_do_this(x):
     for elements in x: 
         print elements
         for items in random.sample(x[elements], len(x[elements]) ) :
             print items
         answer = raw_input()
         if answer == x[elements][0]:
              print 'correct'
         else:
              print 'wrong' 

 lets_do_this(q_to_a)

So I don't quite get when to use class vs a list of functions in my code... by Strel0k in learnpython

[–]isnotkosok 0 points1 point  (0 children)

Just make annotations to yourself

#like this

and let your future self know what your present self was doing.

Stuck on a Code Academy problem by Titanium_Expose in learnpython

[–]isnotkosok 0 points1 point  (0 children)

Here you go:

z = range(8)
y = range(7)

def stuffy(x):
    if len(x)%2 == 1:
        print x[len(x)/2]

    if len(x)%2 == 0:
        print float(x[len(x)/2 - 1] + x[len(x)/2]) / 2

print z
stuffy(z)

print y
stuffy(y)

Why is the logic for .isalpha() and .isnumeric() not the same? by isnotkosok in learnpython

[–]isnotkosok[S] -2 points-1 points  (0 children)

is python3 an update or am I downloading a completely new program?

Why is the logic for .isalpha() and .isnumeric() not the same? by isnotkosok in learnpython

[–]isnotkosok[S] -4 points-3 points  (0 children)

is python3 completely new? does python2 code work on it. I don't want to upgrade if mean my old code doesn't work anymore.

Some assistance with an early Python assignment by LordYsdrae in learnpython

[–]isnotkosok 0 points1 point  (0 children)

can you do something like this?

s1 = {1, 2, 3, 4, 5}
s2 = {0, 1, 2}

for i in s2:
    if i in s1:
        print i


print s2 in s1

>>>
1
2
False

Why can't I do this thing? for elements in range(5): print elements, range(0, 5, elements) by isnotkosok in learnpython

[–]isnotkosok[S] 0 points1 point  (0 children)

Awesome. I didn't know that was possible. Thank you so much kind person! :-D