darkprinx/break-the-ice-with-python

Query, Discussion & Bug Report

darkprinx opened this issue ยท 214 comments

Hello Guys

If anyone wants to -

  • Share opinion
  • Ideas
  • Have query
  • Find mistake

Please feel free to write it down and discuss here.


Sharing new questions and solutions are warmly welcome. Be a proud contributor of this repository by just making a pull request of your changes.

Solution Can be of question 14:
string=input("Enter the sentense")
upper=0
lower=0
for x in string:
if x.isupper()==True:
upper+=1
if x.islower()==True:
lower+=1

print("UPPER CASE: ",upper)
print("LOWER CASE: ",lower)

Solution Can be of question 14:
string=input("Enter the sentense")
upper=0
lower=0
for x in string:
if x.isupper()==True:
upper+=1
if x.islower()==True:
lower+=1

print("UPPER CASE: ",upper)
print("LOWER CASE: ",lower)

Added. Thank you :)

In problem 17 How do I terminate this while true condition?????

Just check whether the input is empty or not.

In answer 14, your solution 2, what is '{0}' and '{1}'? I don't understand.

In python, while printing a dynamic value inside a string, there are several ways to format the output string. For example, let's say you have two variables a = 10 and b = 20 and you want to output something like this,

The sum of 10 and 20 is 30

You can do this by writing it in this way,

print("The sum of {0} and {1} is {2}".format(a, b, a + b))

Here 0, 1, 2 inside '{ }' represents the order of a, b and a+b respectively.

However, If the code is written in this way,

print("The sum of {1} and {0} is {2}".format(a, b, a + b))

then the output will be like,

The sum of 20 and 10 is 30

But printing in this way is not very much necessary. It can be also written in this way,

print("The sum of {} and {} is {}".format(a, b, a + b))

which will give the same output as wanted. I was new to python at that timeline so that I learned and used in {0}, {1} style which is actually not mandatory at all.

Thank you :)

Thank you for teaching me.

#This could be the ans for 16
x=input().split(",")
ans=list(filter(lambda x : int(x)%2!=0 ,x))
print(",".join(ans))

#This could be the ans for 16
x=input().split(",")
ans=list(filter(lambda x : int(x)%2!=0 ,x))
print(",".join(ans))

Added to question# 16

Question 38 ans proposition:

tup = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
lt = int(len(tup)/2)
print(tup[:lt], tup[lt:])

Question 38 ans proposition:

tup = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
lt = int(len(tup)/2)
print(tup[:lt], tup[lt:])

Added. Thank you.

Sharing new questions and solutions are warmly welcome. Be a proud contributor of this repository by just making a pull request of your changes.

For Q. 16 the answers are all wrong.

You say square each odd number yet your demo answer just prints odd numbers

The correct answer is:

num = input("Enter numbers: ").split(',')

print (",".join([str(int(x)**2) for x in num if int(x)%2 != 0]))

For Q. 16 the answers are all wrong.

You say square each odd number yet your demo answer just prints odd numbers

The correct answer is:

num = input("Enter numbers: ").split(',')

print (",".join([str(int(x)**2) for x in num if int(x)%2 != 0]))

Yes, I also noticed the mistake. It's now fixed. Thank you for the cooperation :)

Hi! I don't completely understand how the solution for question 9 works.
Why is it a list what is created?
Also, when I run the solution on my computer, the result is not capitalized.

Hi! I don't completely understand how the solution for question 9 works.
Why is it a list what is created?
Also, when I run the solution on my computer, the result is not capitalized.

Hi Leonedott,
I did a little mistake in the given code for python3. Thus, the result wasn't showing to you as expected. The code has been fixed. Now I'm explaining how the solution works.

As the question says, a program that accepts sequence of lines that means the output will come after all the sequence of lines are taken. That's why a list is created to save the processed inputs and then show them all together as output.

The program will take input until there is an empty line. The program will take a line as input, then make it upper case and append in the list. If the program founds any empty string line, it will break and come out of the loop, and then show all the lines which are saved in the list.

If you still have any queries, please feel free to ask. Thank you :)


Sharing new questions and solutions are warmly welcome. Be a proud contributor of this repository by just making a pull request for your changes.

Here's my solution to exercise 17

`lst = []
while True:
x = input(': ')
if len(x)==0:
break;
lst.append(x)

balance = 0
for item in lst:
if 'D' in item:
balance += int(item.strip('D '))
if 'W' in item:
balance -= int(item.strip('W '))
print(balance)`

Thanks so much for these exercises @darkprinx !!!

Here's my solution to exercise 17

`lst = []
while True:
x = input(': ')
if len(x)==0:
break;
lst.append(x)

balance = 0
for item in lst:
if 'D' in item:
balance += int(item.strip('D '))
if 'W' in item:
balance -= int(item.strip('W '))
print(balance)`

Thanks so much for these exercises @darkprinx !!!

Thanks for sharing your solution. There was a little mistake. I corrected it and added it.

Who is the main author plzz telll me sir,@darkprinx

Problem with Question 70.
It says random even integer from 0 to 10. 0 is even. But they left it out.

Who is the main author plzz telll me sir,@darkprinx

I actually mentioned where I get these problems. It's all described here in the readme.
https://github.com/darkprinx/100-plus-Python-programming-exercises-extended

I tend to mention the person as the main author coz the source I found first from his repository.

Problem with Question 70.
It says random even integer from 0 to 10. 0 is even. But they left it out.

It was a mistake in my code of python3. I mistakenly ignored 0 as a member of the list. I fixed it now. Thank you very much for the co-operation :-)

Answer for Question #30
func = lambda a,b: print(max((a,b),key=len)) if len(a)!=len(b) else print(a+'\n'+b)

Question #34 answer
func = lambda :print([i**2 for i in range(1,21)][:5])

Question #34 answer
func = lambda :print([i**2 for i in range(1,21)][:5])

Both solutions are added. Thank you :)

Question #60
The problem statement should be f(0) = 0, otherwise f(5)=501

Question #67 Recursion method

idx = 0
def bs(num,num_list):
global idx
if (len(num_list) == 1):
if num_list[0] == num:
return idx
else:
return "No exit in the list"
elif num in num_list[:len(num_list)//2]:
return bs(num,num_list[:len(num_list)//2])
else:
idx += len(num_list)//2
return bs(num,num_list[len(num_list)//2:])
print(bs(5,[1,5,8,10,12,13,55,66,73,78,82,85,88,99,100]))

@yuan1z Contributions are added. Thank you. :)

Question 2, Method 3 (recursive function) needs a little correction because in case if input 0 the function throw an error but 0! is defined as 1:
The solution is return 1 if x less or equal to 1:

`n = int(input())
def shortFact(x): return 1 if x <= 1 else x*shortFact(x-1)
print(shortFact(n))`

@StartZer0 The bug has been fixed. Thanks for your cooperation :)

Question #88 answer

my_list = [12,24,35,24,88,120,155,88,120,155]
print(sorted(list(set(my_list))))

Question 101 answer using set and list.count
X = input()
my_set = set(X)
arr = []
for item in my_set:
arr.append([item,X.count(item)])
tmp = sorted(arr,key = lambda x: (-x[1],x[0]))
for i in tmp[:3]:
print(i[0]+' '+str(i[1]))

@yuan1z , the solution for #88 will fail for an the input [155, 120, 88, 155, 88, 120, 24, 35, 24, 12] as the question mentioned to reserve the order of input.

Solution for #101 is added. Thank you :)

just another simple solution for question 63, if there is no requirement to use yield:

n = int(input())

for i in range(0, n+1, 2):
  if i < n - 1:
    print(i, end = ',' )
  else:
    print(i)

I think this is not necessary to add another solution for question 101 as the solution is already given, but anyway I shared:

s = list(input())

dict_count_ = {k:s.count(k) for k in s}
list_of_tuples = [(k,v) for k,v in dict_count_.items()]
list_of_tuples.sort(key = lambda x: x[1], reverse = True)

for item in list_of_tuples:
  print(item[0], item[1])

Question 17 upgraded :)

account = 0
while True:
    action = input("Deposit/Whitdrow/Balance/Quit? D/W/B/Q: ").lower()
    if action == "d":
        deposit = input("How much would you like to deposit? ")
        account = account + int(deposit)
    elif action == "w":
        withdrow = input("How much would you like to withdrow? ")
        account = account - int(withdrow)
    elif action == "b":
        print(account)
    else:
        quit()

Question #6
that's my solution for the exercise. i'd like to ask why, if i write return insted of print inside the definition of the function it returns only the last result (i.e. the result with the last number inserted)
import math
def formula (C=50,H=30,*args):

args = input('insert number: ').split(',')
for i in args:
    Q = math.sqrt((2*C*int(i))/H)
    print(round(Q))

formula()

@StartZer0 @AlexanderSro All the solutions provided are added. Thank you very much for the contribution :)

@simonetrav Thanks for your query. I have shared an explaination with your code,

def formula (C=50,H=30,*args):
    args = input('insert number: ').split(',')
    for i in args:
        Q = math.sqrt((2*C*int(i))/H)
        return Q   # <---- if you put return here, then the function will return the value of Q driven from first number.
                   #       The loop will not further continue for all the value given as input.

def formula (C=50,H=30,*args):
    args = input('insert number: ').split(',')
    for i in args:
        Q = math.sqrt((2*C*int(i))/H)
    
    return Q  # <---- if you put return here, then the function will return the value of Q driven from the latest number.
              #       It's because the value of Q always changed and updated inside the loop. As the last update of Q
              #       occurs for the last given input, thus the output is also associated with the last input. 

I don't agree with Question #20.
You are asking for a generator, but your answer provides a list.
Shouldn't the solution be more like this?:

class Divisible:
    
    def by_seven(self, n):
        for number in range(n + 1):
            if number % 7 == 0: yield number


divisible = Divisible()
generator = divisible.by_seven(int(input("Please insert a number. --> ")))
for number in generator:
    print(number)

Solution to Question 95:
num = int(input("Enter num: "))
L = []
while True:
L.append(num)
num = int(input("Enter another: "))

if num == 0:
	break

print(L)

L1 =set(L)

print(f'The runner up is {max(L1)-1}')

Solution to Question 96:
import textwrap

string = input()
width = int(input())

print(textwrap.fill(string,width))

@mishrasunny-coder, hello there. Thanks for the solution you tried to contribute.
Unfortunately, your solution for problem #95 fails for the test case like [1, 4, 9, 6] where the expected output should be 6 but your solution gives 8. Please review the solution and submit again.

The solution to problem #96 is added. Thanks for your contribution :)

I don't agree with Question #20.
You are asking for a generator, but your answer provides a list.
Shouldn't the solution be more like this?:

class Divisible:
    
    def by_seven(self, n):
        for number in range(n + 1):
            if number % 7 == 0: yield number


divisible = Divisible()
generator = divisible.by_seven(int(input("Please insert a number. --> ")))
for number in generator:
    print(number)

Yes, I just saw the problem and ensured it was my mistake at that time. I usually didn't know that the generator indicates something else in python when I inserted it. I have replaced my solution with your one. Thank you very much for correcting and contributing your solution.

UPDATED SOLUTION to QUESTION 95:

num = int(input("Enter num: "))
L = []
while True:
L.append(num)
num = int(input("Enter another: "))

if num == 0:
	break

L1 = list(set(L[:]))
L2 = sorted(L1)

print(L2)

print(f'The runner up is {L2[-2]}')

@mishrasunny-coder, hello there. Thanks for the solution you tried to contribute.
Unfortunately, your solution for problem #95 fails for the test case like [1, 4, 9, 6] where the expected output should be 6 but your solution gives 8. Please review the solution and submit again.

The solution to problem #96 is added. Thanks for your contribution :)

Thanks so much :) I have added the updated solution to Question 95. Thanks for catching the error.

@mishrasunny-coder your updated code has been added to the solution. Thank you :)

Very Easy Solution to Question 22:
L = input().split()
L1 = {i:L.count(i) for i in L}
print(f'the count is {L1}')

In Question 37 it seems unnecessary to make a list first. I suggest this:

def square_of_numbers():
    return tuple(i ** 2 for i in range(1, 21))


print(square_of_numbers()) 

Question #40 asks to return "Yes" only if the input was "yes" or "YES" or "Yes". With your solution things like "yEs", "yeS" and YeS etc. will all print "Yes" which is not what the question is asking for.
The solution by AasaiAlangaram that was added, does work, but i am not sure that naming a variable the same thing as a built in function is right (input). in this case it might not matter, but if you later want to use the input function, you actually can't. Not sure, if this is a training tool, that teaching things like that are very beneficial.

A normal python 2 to python 3 conversion would in my opinion be a lot better than both given python 3 solutions.

text = input("Please type something. --> ")
if text == "yes" or text == "YES" or text == "Yes": 
    print("Yes")
else: 
    print("No")

Hello,

I am looking for the most efficient way of writing a program of array with binary values (0s and 1s) to find a row with max number of 1s.
For example if row 3 has max 1s then output should print row = 3

Hello,

I am looking for the most efficient way of writing a program of array with binary values (0s and 1s) to find a row with max number of 1s.
For example if row 3 has max 1s then output should print row = 3

Can you please give some sample test cases to let us understand more clearly? thank you.

L = input().split()
L1 = {i:L.count(i) for i in L}
print(f'the count is {L1}')

Thank you for the solution idea. It seems a similar solution is already in there which is shared by AnjanKumarG.

@Seawolf159 Thank you very much to notify and explain about problem #40. I have reviewed and fixed it along with removing my solution. I have also added the solutions you have suggested.

Alternative solution for question #17, using list comprehension

lines = []

while True:
        loopInput = input()
        if loopInput == "/done":
            break
        else:
            lines.append(loopInput)

lst = list(int(i[2:]) if i[0] == 'D' else -int(i[2:]) for i in lines)
print(sum(lst))

Faster solution for question #20

class MyGen():
    def by_seven(self, n):
        for i in range(0, int(n/7) + 1):
            yield i * 7

for i in MyGen().by_seven( int(input('Please enter a number... ')) ):
    print(i)

If we can do question 4 in this way?

t1 = tuple()
seq = (34,67,55,33,12,98)
for i in sea:
t1 += seq
break
print(t1)

@TheAnandPal hello and thanks for the solution. The solution works somehow but doesn't fulfill the requirements mentioned in question 4.

@ShalomPrinz solution for question 17 and 20 is added. Thank you.

Hello Guys

If anyone wants to -

  • Share opinion
  • Ideas
  • Have query
  • Find mistake

Please feel free to write it down and discuss here.

Sharing new questions and solutions are warmly welcome. Be a proud contributor of this repository by just making a pull request of your changes.

Hello Guys

If anyone wants to -

  • Share opinion
  • Ideas
  • Have query
  • Find mistake

Please feel free to write it down and discuss here.

Sharing new questions and solutions are warmly welcome. Be a proud contributor of this repository by just making a pull request of your changes.

I have come up the issue
The solution given isn't supported my Python 3
I would love if my solution becomes a part of your repository

s = 'hello world!hello world!hello world!hello world!'
#In Python 3 zlib.compress() accepts only DataType <bytes>
y = bytes(s, 'utf-8')
x = zlib.compress(y)
print(x)
print(zlib.decompress(x))

@anas1434 Thats great! Can you please let me know which problem number the solution is for?

@anas1434 Thats great! Can you please let me know which problem number the solution is for?

Problem 76 it is.๐Ÿ˜

@anas1434 added. Thank you :)

I have a question regarding number 13. I took a whole different round and used regular expressions to solve (putting the values into a dictionary, which is slightly different than asked, but I wanted to practice that skill). Here's what I did:

import re

input_string = input('> ')

counter = {"LETTERS":len(re.findall("[a-zA-Z]", input_string)), "NUMBERS":len(re.findall("[0-9]", input_string))}

print(counter)

I understand that there are numerous way to solve problems. So my question is, are there any disadvantages to the way I've solved this compared to given answers (basically iterating over the characters of the string). For example, is it potentially slower? Is there an unwritten rule not to import modules when they aren't needed for the solution?

Regarding Question 17, I have a different solution (pretty similar thinking to some of the others):

transactions = []

while True:
    text = input("> ")
    if text:
    	text = text.strip('D ')
    	text = text.replace('W ', '-')
    	transactions.append(text)
    else: break	
transactions = (int(i) for i in transactions)

balance = sum(transactions)


print(f"Balance is {balance}")

I have a question regarding number 13. I took a whole different round and used regular expressions to solve (putting the values into a dictionary, which is slightly different than asked, but I wanted to practice that skill). Here's what I did:

import re

input_string = input('> ')

counter = {"LETTERS":len(re.findall("[a-zA-Z]", input_string)), "NUMBERS":len(re.findall("[0-9]", input_string))}

print(counter)

I understand that there are numerous way to solve problems. So my question is, are there any disadvantages to the way I've solved this compared to given answers (basically iterating over the characters of the string). For example, is it potentially slower? Is there an unwritten rule not to import modules when they aren't needed for the solution?

The solution you have given is quite interesting and different. I appreciate the way you did it. The main focus of the whole repository is to solve a particular problem in different ways. Thus, it helps to understand the language more.

The solution you shared is faster than the other solutions in there. You can check by yourself by generating long strings of 10^6 to 10^7 characters and compare the time.

I don't know much whether there is any specific rule for not importing unused modules. But the good practice will be not to import modules if that is not used. It helps with the readability of the code and will not confuse the reader.

Both solutions to problem number 13 and 17 are added. Thank you very much. :)

I have a question about Question 34:

In the provided answer, the code iterates over the first five items in the list and prints them. Is there an advantage to do it this way over printing the index (or rather slicing the list?):

def squares(n):
	    squares_list = [i**2 for i in range(1,n+1)]
	    print(squares_list[0:5])
squares(20)

(I decided to make the function with an argument so that it can be squares of any number 0 to n)

And a similar thought for #35

def squares(n):
	squares_list = [i**2 for i in range(1,n+1)]
	print(squares_list[-5:])
squares(20)

Again, I know there are lots of different ways to do things, it's just that few resources talk about the advantages of different methods or if there is some sort of hierarchy or unwritten conventions of the best practices.

Question 62:
I had a different way of solving it, but using pretty similar ideas. Again, I put it in a function, because it feels tidier that way.

def fibo(n):
	if n < 2: return n
	return fibo(n-1)+fibo(n-2)

def print_fiblist(n):
	fib_list = [(str(fibo(i))) for i in range(0, n+1)]
	return print(",".join(fib_list))
n = int(input())
print_fiblist(n)

Question 17:
I have different approach

total = 0
while True:
print('Choice the option:')
print('1.Deposit, 2.Withdrawl, 3.Exit')
choice = input()
if choice == '1':
print('Enter amount to deposit')
while True:
d = input('')
if len(d) != 0:
v = int(d)
total += v
else :
break

elif choice == '2' :
print('Enter amount to Withdrawl')
while True:
w = input('')
if len(w) != 0:
v = int(w)
total -= v
else :
break

else :
break
print('')
print('Total Balance ',total)

@popomaticbubble solutions provided in the first place are given in a way so that it can be as simple as possible for a beginner. Not else reason actually. your provided solutions are added. Thank you :)

Hello darkprinx,

Thank you for the interesting exercises! I have an alternative solution to exercise #6, based on the solution you provided to exercise 1.

from math import sqrt
C, H = 50, 30
mylist = input().split(',')
print(*(round(sqrt(2*C*int(D)/H)) for D in mylist), sep=",")

Hello darkprinx,

I think that there is a typo in solution 2 to exercise #9.
With while input(), only every second input is considered.

lst = []

while input(): # I think it should be while True:
    x = input()
    if len(x)==0:
        break
    lst.append(x.upper())

for line in lst:
    print(line)

Hello darkprinx,

I think that there is a typo in solution 2 to exercise #9.
With while input(), only every second input is considered.

lst = []

while input(): # I think it should be while True:
    x = input()
    if len(x)==0:
        break
    lst.append(x.upper())

for line in lst:
    print(line)

Yes, you are right. That was a mistake.Thank you :)

Solution Can be of question 15:

from functools import reduce
x = input('please enter a digit:')
# reduce(lambda x, y: int(x) + int(y), [x, x * 2, x * 3, x * 4])
reduce(lambda x, y: int(x) + int(y), [x*i for i in range(1,5)])

Solution Can be of question 17:

money = 0
while 1:
    trans = input().split(' ')
    if trans[0] == 'D':
        money = money + int(trans[1])
    elif trans[0] == 'W':
        money = money - int(trans[1])
    elif input() == '':
        break
    print(f'Your current balance is: {money}')

@ChichiLovesDonkeys your solutions are added. Thank you :)

Question 15 one liner solution:

def question_15(string_digit):
    return sum(int(string_digit * n) for n in range(1, 5))

@lcastrooliveira solution added. thank you.

Question 3 solution with enumerate:

num = int(input("Number: "))
print(dict(list(enumerate((i * i for i in range(num+1))))))

Question (95):
Solution
num = int(input())
scores = list(map(int,input().split(' ')))
winner = max(scores)
lst = []

if len(scores) != num:
print('lenght of score is greater than input given')

else:
for score in scores:
if winner > score:
lst.append(score)

runnerup = max(lst)
print(runnerup)

Question 2 with reduce:
from functools import reduce
def fun(acc,item):
return acc*item
print(reduce(fun,range(1,num+1), 1))

`while True:
try:
num = int(input("Enter a number: "))
break
except ValueError as err:
print(err)

dictio = dict()
for item in range(num+1):
if item == 0:
continue
else:
dictio[item] = item * item
print(dictio)`

Why did 'while True' implemented here? Either statements following the while loop are not properly indented or the while loop is unnecessarily used. Please correct it.

Code from day 1-problem 3

In question no.5 why are we using init method in it..... without that also its working

In exercise 5, the instructions are to 'also please include simple test function to test the class methods'. I didn't see an example of this in the solution. Would you use unittest? I struggle with writing unittests. I can make it work for my printString function but not my getString function. I think it is a problem with my arguments because of the console input.

@yurbika @KailashS3 @KruthikaSR Solutions are added. Thank you :)

@TheNobleKnight the solution has been corrected. Thank you :)

In question no.5 why are we using init method in it..... without that also it's working.

I used the init method when I was new to python. At that timeline, I thought it's a good convention to keep the init method in every class whether it's used or not. Right now it seems, you are also correct in your point. So, I have removed it from there. Thank you. :)

@kdhenderson looking forward to helping you with the test cases :)

The first exercise of day 7... I really don't understand what the exercise wants the output to be.

On the example, how do I format the output to go from (1,2) do 2?

here is another way to solve question 53 (considering email structure is always the same):

def question_53(user_email):
    return re.search('[a-z]+', user_email).group(0)

print(question_53('yourusername@yourcompany.com'))

question 59 can also be done as:

def question_59(n):
    print(round(sum(map(lambda x: x/(x+1), range(1, n+1))), 2))

question_59(5)

I've managed to make a version of question_62 iteratively

def question_62(n):
    if n == 0:
        return [0]
    if n == 1:
        return [0, 1]
    sequence = [0, 1]
    a = 0
    b = 1
    for x in range(2, n+1):
        c = a + b
        sequence.append(c)
        a = b
        b = c
    return sequence

Question 79 can also be achieved using itertools product. See this link for further reference.

from itertools import product

def question_79():
    subject = ["I", "You"]
    verb = ["Play", "Love"]
    object = ["Hockey", "Football"]
    prod = [p for p in product(range(2), repeat=3)]
    for combination in prod:
        print(f'{subject[combination[0]]} {verb[combination[1]]} {object[combination[2]]}')

hey guys, my solutions for questions 60, 61(not included by could be taken from 62), 62 any thoughts?

def task_60():
    n = 5
    f = lambda x: f(x-1)+100 if x > 0 else 0
    print(f(n))

def task_62():
    n = 7
    f = lambda x: 0 if x == 0 else 1 if x == 1 else f(x-1)+f(x-2)
    print(','.join([str(f(x)) for x in range(0, n+1)]))

Hey, regarding question 19, I noticed that although the solution works for the given input, you may get a wrong output if you use different numbers. As the numbers are in str form, when you try to sort them by just calling x[1] and x[2] as the key, it seems that only the first digit is taken into consideration. In this case, 10 would be seen as lower than 9. My suggestion is to convert the keys related to age and score to int in the lambda function, as in:

lst.sort(key= lambda x:(x[0],int(x[1]),int(x[2]))) 

The following can be another solution for question 6:
my_list = [int(x) for x in input('').split(',')]
C = 50
H = 30
x = []
for D in my_list:
Q = ((2CD)/H)**(1/2)
x.append(round(Q))
print(','.join(map(str,x)))

Another solution for Ques.13 :

Write a program that accepts a sentence and calculate the number of letters and digits.

Suppose the following input is supplied to the program:

hello world! 123

Then, the output should be:

LETTERS 10
DIGITS 3

code

Solution for Ques.15 :

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

Code:

add, a = 0, input("")
for i in range(1, 5):
      int(i*a)
      add += int(i*a)
print(add)

Solution of 17.
total = 0
while True:
option = input("Please choose the option D for deposit and W for withdraw and Q for quit: ")
if option == 'D':
amount = int(input("Please enter deposit the amount: "))
total = total+amount
continue
if option == 'W':
amount = int(input("Please enter withdraw the amount: "))
total = total-amount
continue

if option == 'Q':
    break

print(total)

Question 53:
def get_name(name):
for i in name:
if i == '@':
break
else:
str(i)
print(i,end="")

get_name(input("email: "))

I have another itertools solution to problem 79:

import itertools
subject = ["I", "You"]
verb = ["Play", "Love"]
objects = ["Hockey","Football"]

sentence = [subject, verb, objects]
n = list(itertools.product(*sentence))
for i in n: print(i)