# Neverending Python Challenges Game!

 Aubree Keegan · August 27, 2014 I think that Bucky's challenges are really fun and they are helping me learn too, so here is an idea I just came up with.We will start with a programming challenge. As soon as a user completes that challenge, they will post the answer and also a challenge of their own! This way, we will always have a new problem to work on.Here is my first one:Create a Python program that will complete this song:10 Green Bottles hanging on the wall10 Green Bottles hanging on the wallAnd if one Green Bottle should accidentally fallThere'll be 9 Green Bottles hanging on the wall9 Green Bottles hanging on the wall9 Green Bottles hanging on the wallAnd if one Green Bottle should accidentally fallThere'll be 8 Green Bottles hanging on the wall...Whoever answer first can post the next challenge!

## Replies

- page 1

 Svante Nilsson · September 27, 2014 ``def Fibo(number):    a = 0    b = 1    c = 0    while number > c:        c = a + b        a = b        b = c    if number == c or number == 0:        return True    else:        return Falseprint(Fibo(int(input("Enter your number:"))))``Bumping Jay's challenge:"Create a running game where the player has to press 2 keys a certain number of times as if they were controlling legs and it times the time taken to 'run' the distance as well as somehow showing progress to the finish " Samuel Oloruntoba · September 26, 2014 ``def is_prime(num):    prime = True     for i in range(2, num):       if num % i == 0:           prime = False           break    return prime    if is_prime(11):    print('cool number')else:    print('this number sucks')``a simple function to check if a number is part of a fibonacci series. Bor GS · September 26, 2014 ``def narcissistic(n):    digitlist=list(str(n))    for i in range(len(digitlist)):        digitlist = int(digitlist)        digitlist **= len(digitlist)       if sum(digitlist) == n:        return True    else:        return Falseprint(narcissistic(input()))``Type a program that checks if the number is prime. Jay Tauron · September 10, 2014 Made a hangman game I omitted the word list again, for cleaner reading.It takes a list of single or multiple word strings.``import randomimport osclass Hangman:    word_list = ['''look at comment above''']    miss_count = 0    guessed_letters = []    misses = []    def __init__(s):        print("Welcome to Hangman!")        while s.play():            w = s.new_ran_word()            letters = list(w)            s.guessed_letters = []            s.misses = []            s.miss_count = 0            while s.miss_count < 13:                s.print_hangman(s.miss_count)                s.word_print(w)                s.print_misses()                if s.word_is_complete(w):                    print("You got the word!\n")                    break                try:                    g = input("Guess: ").upper()[0]                except IndexError:                    continue                if g in s.guessed_letters:                    continue                s.guessed_letters += g                if g not in letters:                    s.miss_count += 1                    if s.miss_count == 12:                        s.print_hangman(s.miss_count)                        print("Oh no! You died!")                        print("The word was", w.upper())                        break                    else:                        s.misses += g                        print("Oops! Make another guess")                else:                    print("Correct!")    def play(s):        a = input("Press [enter] to continue or [any key][enter] to exit\n")        if a != '':            print("\nThanks for playing!\n")            return False        return True    def print_hangman(s, c):        s.clear()        if c < 5:            a = "-"*c            print(a)        else:            print("-----")        if c > 5:            print("|   |")        else:            print("|")        if c > 6:            print("|   o")        else:            print("|")        if c > 9:            print("|  -|-")        elif c > 8:            print("|  -|")        elif c > 7:            print("|   |")        else:            print("|")        if c > 11:            print("|   ?")            print("|  / \\")        elif c > 10:            print("|   ?")            print("|  /")        else:            print("|")            print("|")        print("|")        print("-----\n")    def new_ran_word(s):        l = s.word_list        return l[random.randrange(len(l))].upper()    def word_print(self, w):        s = "Word: "        for l in w:            if l in self.guessed_letters:                s += l + " "            elif l == " ":                s += "/ "            else:                s += "_ "        print(s)    def print_misses(self):        s = "Misses: "        for l in self.misses:            s += l.lower()            if l != self.misses[-1]:                s += ", "        print(s)    def word_is_complete(s, w):        for l in w:            if l == " ":                continue            if l not in s.guessed_letters:                return False        return True    def clear(s):        os.system('cls' if os.name == 'nt' else 'clear')hangman = Hangman()``Create a running game where the player has to press 2 keys a certain number of times as if they were controlling legs and it times the time taken to 'run' the distance as well as somehow showing progress to the finish Jay Tauron · September 9, 2014 This is my solution to Samuel's problem, I hope it fits the criteria.This is for Python 3.4Omitted the word list for cleaner reading for you guys  - it is designed to take a list of single word strings``import randomclass Scramble:    word_list = [''' look at comment above ''']    count = 0    attempts = 0    correct = 0    wrong = 0    def __init__(s):        print("Welcome to Scramble!")        while s.play():            word = s.new_ran_word()            scrambled = s.scramble(word)            s.count += 1            s.attempts += 1            print("--------")            print("Round", s.count)            phrase = "Guess the scrambled word:\n" + scrambled + "\n> "            guess = input(phrase)            while s.attempts < 4:                if guess.lower() == word:                    s.correct_ans()                    break                elif s.attempts == 3:                    print("Oops! The word was", word, "\n")                    s.wrong += 1                    s.attempts = 0                    break                else:                    guess = input("Try again!\n> ")                    s.attempts += 1    def play(self):        a = input("Press [enter] to continue or [any key][enter] to exit\n")        if a != '':            print("--------Stats--------")            print("Words attempted:  ", self.count)            print("Correct guesses:  ", self.correct)            print("Incorrect guesses:", self.wrong)            score = self.get_score()            print("You scored " + score + "%")            print("\nThanks for playing!\n")            return False        return True    def new_ran_word(self):        l = self.word_list        return l[random.randrange(len(l))].lower()    def scramble(self, w):        pos_taken = []        new = list(w)        for x in w:            new_pos = random.randrange(len(w))            while new_pos in pos_taken:                new_pos = random.randrange(len(w))            pos_taken.append(new_pos)            new[new_pos] = x        s = ""        for c in new:            s += c        if s == w:            return self.scramble(w)        else:            return s    def correct_ans(s):        print("Well done!")        print("You got it in", s.attempts, "attempt(s)!\n")        s.attempts = 0        s.correct += 1    def get_score(s):        try:            return str(int(s.correct*100/s.count))        except ZeroDivisionError:            return "0"scramble = Scramble()``For the next question, I will go back to Mason's question of a madlibs game Samuel Oloruntoba · September 3, 2014 @jay, you did not ask a question, so i guess i can ask but since i don't know what madlibs are here is my own rock paper scissors solution, it is quite bulky but you can check it out at this url(https://github.com/kayandrae/BR-ROCK_PAPER_SCISSORS/blob/master/main.py) my own question is, a word is chosen from by the computer from a group of words, this particular word is mis-arranged, the user has 3 chances to spell the right word. Jay Tauron · September 3, 2014 ``def pyramid(size):    rows = size    blocks = 1    spaces = size    for x in range(rows): s = ""        for z in range(spaces):            s += " "        for y in range(blocks):            s += "*"        blocks += 2        spaces -= 1        print(s)pyramid(20)``Python 3.4 compatible pyramid problem, with a few changes Mason Farina · September 3, 2014 ``import randomuserchoice = input("Please enter either rock, paper or scissors: ")_enemyChoice = ["rock","paper","scissors"]enemyChoice = _enemyChoice[random.randint(0,2)]print("the computer chose: "+enemyChoice)print("the player chose: "+userchoice)if userchoice == "rock" and enemyChoice == "paper":    print("the computer wins")if userchoice== "rock" and enemyChoice== "rock":    print("the it's a tie")if userchoice== "rock" and enemyChoice== "scissors":    print("the player wins")if userchoice== "scissors" and enemyChoice== "rock":    print("the computer wins")if userchoice== "scissors" and enemyChoice== "scissors":    print("its a tie")if userchoice== "scissors" and enemyChoice== "paper":    print("the computer wins")if userchoice== "paper" and enemyChoice== "scissors":    print("the computer wins")if userchoice== "paper" and enemyChoice== "paper":    print("its a tie")if userchoice== "paper" and enemyChoice== "rock":    print("the player wins")``Make a madlibs type game Nikola Pantelić · September 3, 2014 ``num=371num=str(num)chars=len(num)result=0for i in range(0,chars):    result+=int(num)**charsif result==int(num):    print('Number is narcissistic!')else:    print('Sorry, number is not narcissistic...')``Make a Rock, Paper, Scissors game! Yoncho Yonchev · September 1, 2014 Anything more challenging will be nice. Providing alternative solutions for old tasks is fine too. ``# Python 3.4, authour: yonchoy# removing whitespaces from the inputsentence=str(input()).replace(" ", "")# creating dictionary containing how many times each letter exist, unfortunately doesnt work for dublicates#will show the last entered with the same key in the dictionarydef char_histogram(sentence):    return {sentence.count(ch):ch for ch in set(sentence)}my_dic=char_histogram(sentence)print(my_dic[max(my_dic.keys())])``Program that checks if number is narcissistic (http://en.wikipedia.org/wiki/Narcissistic_number)
• 1
• 2

## Python

109,637 followers