Posts

According To Data Science Topic 16 Sequence sum Task

  # sequence sum # 1/1! + 2/2! + 3/3! + ... + n/n! n = int(input('enter n')) result = 0 fact = 1 for i in range(1,n+1):   fact = fact * i   result = result + i/fact   print(result) Result: enter n1 1.0 enter n2 1.0 2.0 enter n3 1.0 2.0 2.5 enter n4 1.0 2.0 2.5 2.6666666666666665 enter n5 1.0 2.0 2.5 2.6666666666666665 2.708333333333333   

According to Data Science Topic-15 For loop and examples

 # for loop demo for i in range(1,11):  print(i) Result: 1 2 3 4 5 6 7 8 9 10 for i in range(1,11,3):   print(i) Result: 1 4 7 10 for i in range(10,0,-1):   print(i) Result: 10 9 8 7 6 5 4 3 2 1 i = 'delhi' for i in 'delhi':   print(i) Result: d e l h i for i in [1,2,3,4,5]:   print(i) for i in (1,2,3,4,5):   print(i) for i in {1,2,3,4,5}:   print(i) Result: 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 # Program - The current population of the town is 10000. The population of the town is increasing at the rate of 10% per year. You have to write a program to find out the population at the end of each of the last 10 years. curr_pop = 10000 for i in range(10,0,-1):   print(i,curr_pop)   curr_pop = curr_pop - (curr_pop/1.1) Result: 10 10000 9 909.0909090909099 8 82.6446280991737 7 7.513148009015794 6 0.6830134553650726 5 0.062092132305915704 4 0.005644739300537799 3 0.0005131581182307096 2 4.665073802097362e-05 1 4.240976183724878e...

According to Data Science Topic-14 While loop examples

  # While loop example -> program to print the table # Program -> Sum of all digits of a given number # Program -> Keep accepting numbers from users till he/she enters a 0 and then find the average number = int(input('enter the number')) i = 1 while i <= 11:   print(number, 'x', i, '=', number * i)   i = i + 1 Result: enter the number11 11 x 1 = 11 11 x 2 = 22 11 x 3 = 33 11 x 4 = 44 11 x 5 = 55 11 x 6 = 66 11 x 7 = 77 11 x 8 = 88 11 x 9 = 99 11 x 10 = 110 # while loop with else11 x = 1 while x < 3:   print(x)   x += 1 else:   print('limit crossed') Result:1 2 limit crossed # guessing game # generate a random integer between 1 and 100 import random jackpot = random.randint(1, 100) guess = int(input('Guess the number: ')) counter = 1 while guess != jackpot:     if guess < jackpot:         print('Incorrect! Guess higher.')     else:         print('Incorrect! Guess lower.') ...

According to Data Science Topic-13 Modules

 # Modules in Python # 1-math # 2-keywords # 3-random # 4-datetime # math import math  print(math.factorial(5))  print(math.floor(6.8))  print(math.sqrt(196)) Result: 120 6 14.0 # keyword import keyword print(keyword.kwlist) Result: ['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'] # random import random print(random.randint(1,100)) Result:48 # datetime import datetime print(datetime.datetime.now()) Result: 2024-01-13 15:42:37.384551 help('modules')

According to Data Science Topic-12 If else program examples

  # email- abhayprasad.36480@gmail.com # password-1234 email = input('Enter your email: ') password = input('Enter your password: ') if email == 'abhayprasad.36480@gmail.com' and password == '1234':   print('Welcome') elif email == 'abhayprasad.36480@gmail.com' and password != '1234':   # tell the user   print('Incorrect password')   password = input('enter password again')   if password == '1234':     print('Welcome,finally!')   else:     print('beta tumse na ho payega!') else:   print('Not correct') Result: Enter your email: abcd Enter your password: 7689 Not correct Enter your email: abhayprasad.36480@gmail.com Enter your password: 1234 Welcome Enter your email: abhayprasad.36480@gmail.com Enter your password: 4567 Incorrect password enter password again9000 beta tumse na ho payega! Enter your email: abhayprasad.36480@gmail.com Enter your password: 4567 Incorrect password enter pa...

According to Data Science Topic-11 one program for Operators

 number = int(input("Enter a number: ")) print(number) # 345%10 -> 5 a = number%10 # 345%10 -> 34 number = number//10 # 34%10 -> 4 b = number % 10 number = number//10 # 3 % 10 -> 3 c = number % 10 print(a+b+c) Result:  Enter a number: 345 345 12 Enter a number: 666 666 18

According to Data Science Topic-10 Operators

 # Arithmetric Operators print(5+6) print(5-6) print(5*6) print(5/2) print(5//2) print(5%2) print(5**2) Result: 11 -1 30 2.5 2 1 25 # Relational Operators print(4>5) print(4<5) print(4>=4) print(4<=4) print(4==4) print(4!=4) Result: False True True True True False # Logical Operators print(1 and 0) # (00 and 01) print(1 or 0) print(not 1) Result: 0 1 False # Bitwise Operators # bitwise and print(2 & 3) # bitwise or print(2 | 3) # bitwise xor print(2 ^ 3) print(~3) print(4 >> 2) print(5 << 2) Result: 2 3 1 -4 1 20 # Assignment Operators # =  # a = 2 a = 2  # a = a % 2 # a = a + 2 # a %= 2 a += 2 # a++ ++a(This is not used in python) print(a) Result: 4 # Membership Operators # in/not in print('D' not in 'Delhi') print(1 in [2,3,4,5,6]) Result: False False