Wednesday, 23 January 2019

Question 4
Level 1

Question:
Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
Suppose the following input is supplied to the program:
34,67,55,33,12,98
Then, the output should be:
['34', '67', '55', '33', '12', '98']
('34', '67', '55', '33', '12', '98')

Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
tuple() method can convert list to tuple

Solution:

values=input("Enter a number : ")
l=values.split(",")
t=tuple(l)
print(l)
print(t)

Output:-
Enter a number : 7,8,9,10,11,12,13,14,15
['7', '8', '9', '10', '11', '12', '13', '14', '15']
('7', '8', '9', '10', '11', '12', '13', '14', '15')

Question 3Level 1


Question:
With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.
Suppose the following input is supplied to the program:
8
Then, the output should be:
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}

Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
Consider use dict()

Solution:

n=int(input("Enter a number: "))
d=dict()
for i in range(1,n+1):
d[i]=i*i

print(d)

Output:-
Enter a number: 8
{1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}

New Question :

Write a program which can compute the factorial of a given numbers.
The results should be printed in a comma-separated sequence on a single line.
Suppose the following input is supplied to the program:
8
Then, the output should be:
40320

Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.

Solutions:-

def fact(x):
if x == 0:
return 1
return x * fact(x - 1)

x=int(input("Enter a a number : "))
print(fact(x))

Output:-
Enter a a number : 5
120

Monday, 21 January 2019

Here is 2nd Challenge for Python Practice 
Question 2:-
3 product enter than you show what is billning product and what is free product
2K < == 5%
2k - 5k == 10%
5K- Above == 20%
discount first calculate than count tax
total * 5/100
toatal * 10/100
total * 20/100

Solutions ==> 

a = int(input("Enter First Product Price : "))
b = int(input("Enter Second Product Price : "))
c = int(input("Enter Third Product Price : "))
def buy_get_one_free(p1,p2,p3):
free = 0
if b > a < c:
free += a
elif a > b < c:
free += b
else:
free += c
return free

print(f"Free Product is {buy_get_one_free(a,b,c)}")
total = a+b+c-(buy_get_one_free(a,b,c))
print(f"Total product Value : {total}")

def tax(t):
tax = 0
if total < 2000:
tax += 0
elif 4000 < total > 2000:
disc = (total * 5)/100
tax += disc
elif 4000 < total > 6000:
disc = (total * 10)/100
tax += disc
elif total > 6000:
disc = (total*20)/100
tax += disc
return tax

print(f"Your Discount Value is {tax(total)}")
print(f"Your Total Paid Amount is {total-tax(total)}")



Output ==> 
Enter First Product Price : 50000
Enter Second Product Price : 60000
Enter Third Product Price : 70000
Free Product is 50000
Total product  Value : 130000
Your Discount Value is 6500.0
Your Total Paid Amount is 123500.0

Saturday, 19 January 2019

Here is First Challenge


Question 1

Level 1

Question:
Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
between 2000 and 3200 (both included).
The numbers obtained should be printed in a comma-separated sequence on a single line.

Solutions===>

l=[]
for i in range(2000, 3201):
if (i%7==0) and (i%5!=0):
l.append(str(i))
print( ','.join(l))