Neverending Python Challenges Game!

+11 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 wall
10 Green Bottles hanging on the wall
And if one Green Bottle should accidentally fall
There'll be 9 Green Bottles hanging on the wall

9 Green Bottles hanging on the wall
9 Green Bottles hanging on the wall
And if one Green Bottle should accidentally fall
There'll be 8 Green Bottles hanging on the wall

...


Whoever answer first can post the next challenge!  :happy:

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
+2 Gary Murphy · August 29, 2014
http://colbertnation.mtvnimages.com/images/shows/colbert_report/videos/season7/mashups/cr_mashup_routines_I_did_it_v6.jpg


newNumber = ""
number = str(raw_input("Enter your number: "))
for i in number:
    newNumber = i + newNumber
if number == newNumber:
    print("The number is a palindrome")
else:
    print("The number is not a palindrome")


Write a piece of code that takes in any string and returns the most used character in that string.
0 Nikola Pantelić · August 27, 2014
Oh... I think I read it wrong! Nevermind, I will edit the code :D
+1 Eugene Botma · August 27, 2014
Nikola, a panagram is a sentence that uses all of the letters in the alphabet, repeating letters doesn't matter.
+1 Nikola Pantelić · August 27, 2014
### alph is alphabet
### sen is sentence
### k is variable used to check if the character doesn't appear (1=char is in sentence,0=char is not in sentence)
### I used sen.lower() to convert all characters to lower before comparing them
alph="abcdefghijklmnopqrstuvwxyz"
sen="The quick brown fox jumps over the lazy dog"
k=0
sen=sen.lower()
for i in range(0,len(alph)):
    for j in range(0,len(sen)):
        while sen[j]==" ":
            j+=1
        if alph==sen[j]:
            k=1
            break
    if k==0:
        print("Sorry, sentence is not a pangram!")
        exit(0)
    k=0
print("Sentence is pangram!")

Type a program that checks if the number is palindrome! Example: Numbers 1221 and 467764 are palindromes (they are same when you read them from behind)
+2 Yoncho Yonchev · August 27, 2014

from random import randint

l=[2,3,4,5,6,7,8,9,10,'J','Q','K','A']
n1,n2,n3,n4=randint(0,12),randint(0,12),randint(0,12),randint(0,12)

def count_cards(n):
   if n+2 <=10:
      return n+2
   else:
      return 10

print('Dealer has: ' +str(l[n1])+' '+str(l[n2])+'='+str(count_cards(n1)+count_cards(n2)))
print('You have: ' +str(l[n3])+' '+str(l[n4])+'='+str(count_cards(n3)+count_cards(n4)))
if (n1+n2) <(n3+n4):
   print('You win!')
else:
   print('You loose!')

Program, that check is a sentence is panagram in English -> Example:"The quick brown fox jumps over the lazy dog" - contains all letters of the English alphabet.
+1 Ramanpreet Kaur · August 27, 2014
This works, but I am getting a warning for some reason  :(

ramanpreet = ['Newton', 'House', 'Dog', 'Computer', 'Programming']
ramanpreet.sort(key=len)
print(ramanpreet)

# output
# ['Dog', 'House', 'Newton', 'Computer', 'Programming']

This is my warning:

Expected type '(str) -> object | None' (matched generic type '(T) -> object | None'), got '(object: Sized) -> int' instead less... (Ctrl+F1)
This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations.


I don't understand what this means. Can anyone help? And it does work, so here is my next challenge. 

Create a simple program that randomly deals you and the dealer two cards each. The highest total wins! (the output should look like this)
Dealer has: K 7 = 17
You have:   J 3 = 13

You lose.
+3 Tommy Hillis · August 27, 2014
I got this!

/images/forum/upload/2014-08-27/6d4386b3e66128cd4bc36d18209325e5.png

fridays = 0

for days in range(1, 366):
    if days % 7 is 5:
        print("Day", days, "is a Friday")
        fridays += 1

print("\nThere are", fridays, "Fridays this year!")


For the next challenge, let the user input any number, and print a start pyramid with that many rows. For example if they said 5:

    *
   ***
  *****
 *******
*********
+4 Emily Cash · August 27, 2014
/images/forum/upload/2014-08-27/1dcd043f993ee3a93d59eef7005b43aa.png

num = 10
while num > 0:
    print(num, "Green Bottles hanging on the wall")
    print(num, "Green Bottles hanging on the wall")
    print("And if one Green Bottle should accidentally fall")
    num -= 1
    print("There'll be", num, "Green Bottles hanging on the wall\n")

Next challenge: If a year (365 days) starts on a Monday, find out how many Fridays are in that year  :)
  • 1
  • 2

Python

107,326 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator