Sample codes in Python

factorialFactorial of an input number by looping and by recursive functions
factorsFactors of an input number
Prime NumbersPrime Numbers
FibonacciFibonacci numbers by looping and by recursive functions
Sum of DigitsSum of digits of an input number
Multiplication tableMultiplication table using nested for loops
strong numberCheck input number is strong number or not
Armstrong numberCheck input number is Armstrong number or not
Digit CubesNumber equal to sum of cubes of its digits

Sum of three user input numbers

int() to get Integer from String
a=int(input("Enter first Number"))
b=int(input("Enter second Number"))
c=int(input("Enter third Number"))
sum=a+b+c
print(sum)

Enter mark to get status of your division

 m=int(input("Enter your marks"))
if(m>=90):
    print("You have Passed with First Distinction")

else:
    if(m>=60):
        print("You have passed with Second Distinction")
    else:
        if(m>=35):
            print("You have just passed work hard next time")
        else:
            print("Failed")
In place of using multiple if else , it is better to use elif.
Read more how to use elif to get the grade from input mark.

Converting Decimal to Binary number

def my_binary(n):
    i=''
    while n>1:
        a = n%2
        n = n//2
        i=str(a)+i
    i=  str(n%2) +i   
    print (i)
    
a=my_binary(156) 

round a number without using round() function

x=float(input("input number "))
y=int(x+0.5)
print(y)


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer