diff --git a/My-solutions/100 python exercises - ex14.py b/My-solutions/100 python exercises - ex14.py new file mode 100644 index 00000000..47bf99b9 --- /dev/null +++ b/My-solutions/100 python exercises - ex14.py @@ -0,0 +1,31 @@ +# 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 diff --git a/My-solutions/100 python exercises - ex15.py b/My-solutions/100 python exercises - ex15.py new file mode 100644 index 00000000..3c701032 --- /dev/null +++ b/My-solutions/100 python exercises - ex15.py @@ -0,0 +1,41 @@ +# 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: (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: # Create a list of integers of the digit repeated p times + sequence.append(int(str(digit) * p)) + for p in sequence: # Add the resulting values + 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