From 0fc44e08fe3cfb413ee078dde978a1c108cad846 Mon Sep 17 00:00:00 2001 From: pecopiano Date: Thu, 11 Dec 2014 13:50:53 +0100 Subject: [PATCH 1/5] Create 100 python exercises - ex15.py --- 100 python exercises - ex15.py | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 100 python exercises - ex15.py diff --git a/100 python exercises - ex15.py b/100 python exercises - ex15.py new file mode 100644 index 00000000..e48817e0 --- /dev/null +++ b/100 python exercises - ex15.py @@ -0,0 +1,40 @@ +# Question 15 +# Level 2 +# +# Question: +# Write a program that computes the value of a+aa+aaa+aaaa +# with a given digit as the value of a. + +# Suppose the following input is supplied to the program: +# 9 +# Then, the output should be: +# 11106 +# + +# Function: +# 1 - Ask a digit +# 2 - Ask how many time it should be added (2--> a + aa / 4--> a + aa + aaa + aaaa) + + +def conv(digit, repeats): + start = range(1,repeats+1) + sequence = [] + count = 0 + for p in start: + sequence.append(int(str(digit) * p)) + for p in sequence: + count = count + p + return count + +digit = int(raw_input("digit? ")) +repeats = int(raw_input("repeats? ")) + +print conv(digit,repeats) + +# Book's Solution: +# a = raw_input() +# n1 = int( "%s" % a ) +# n2 = int( "%s%s" % (a,a) ) +# n3 = int( "%s%s%s" % (a,a,a) ) +# n4 = int( "%s%s%s%s" % (a,a,a,a) ) +# print n1+n2+n3+n4 From 06c994591f4df099cb9bad90599ea720636363c7 Mon Sep 17 00:00:00 2001 From: pecopiano Date: Thu, 11 Dec 2014 13:54:01 +0100 Subject: [PATCH 2/5] Update 100 python exercises - ex15.py --- 100 python exercises - ex15.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/100 python exercises - ex15.py b/100 python exercises - ex15.py index e48817e0..3c701032 100644 --- a/100 python exercises - ex15.py +++ b/100 python exercises - ex15.py @@ -11,18 +11,19 @@ # 11106 # -# Function: +# Function: (taking the assignment a bit further!) # 1 - Ask a digit # 2 - Ask how many time it should be added (2--> a + aa / 4--> a + aa + aaa + aaaa) +# Ask the user a digit, and how many times it should be repeated then added to the other repetitions def conv(digit, repeats): start = range(1,repeats+1) sequence = [] count = 0 - for p in start: + for p in start: # Create a list of integers of the digit repeated p times sequence.append(int(str(digit) * p)) - for p in sequence: + for p in sequence: # Add the resulting values count = count + p return count From e58e8d68901af97e8247982a5deb8941db24fc77 Mon Sep 17 00:00:00 2001 From: pecopiano Date: Thu, 11 Dec 2014 14:00:15 +0100 Subject: [PATCH 3/5] Create 100 python exercises - ex14.py --- My-solutions/100 python exercises - ex14.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 My-solutions/100 python exercises - ex14.py diff --git a/My-solutions/100 python exercises - ex14.py b/My-solutions/100 python exercises - ex14.py new file mode 100644 index 00000000..c0a18dce --- /dev/null +++ b/My-solutions/100 python exercises - ex14.py @@ -0,0 +1 @@ +ze From 264bad4bea4ad8ffa3e55c40d94909fbf81d2c15 Mon Sep 17 00:00:00 2001 From: pecopiano Date: Thu, 11 Dec 2014 14:02:48 +0100 Subject: [PATCH 4/5] Rename 100 python exercises - ex15.py to My-solutions/100 python exercises - ex15.py --- .../100 python exercises - ex15.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename 100 python exercises - ex15.py => My-solutions/100 python exercises - ex15.py (100%) diff --git a/100 python exercises - ex15.py b/My-solutions/100 python exercises - ex15.py similarity index 100% rename from 100 python exercises - ex15.py rename to My-solutions/100 python exercises - ex15.py From cd9c168f0967663144cb6d6fdaa0ea92053eea80 Mon Sep 17 00:00:00 2001 From: pecopiano Date: Thu, 11 Dec 2014 14:03:24 +0100 Subject: [PATCH 5/5] Update 100 python exercises - ex14.py --- My-solutions/100 python exercises - ex14.py | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/My-solutions/100 python exercises - ex14.py b/My-solutions/100 python exercises - ex14.py index c0a18dce..47bf99b9 100644 --- a/My-solutions/100 python exercises - ex14.py +++ b/My-solutions/100 python exercises - ex14.py @@ -1 +1,31 @@ -ze +# Question 14 +# Level 2 +# +# Question: +# Write a program that accepts a sentence +# and calculate the number of upper case letters and lower case letters. + +# Suppose the following input is supplied to the program: +# Hello world! +# Then, the output should be: +# UPPER CASE 1 +# LOWER CASE 9 + +import re + +test_string = "Hello World! WORLD And whatever the hell that MEANS" + +split = ''.join(re.split(r'\W+', test_string)) + +upper = 0 +lower = 0 + +for p in split: + if p.isupper(): + upper += 1 + elif p.islower(): + lower += 1 + + +print upper +print lower