0% found this document useful (0 votes)
79 views

Basic Python Program For Class 11: 1. Hello Word Print ("Hello World")

This document provides examples of 18 basic Python programs including: 1) Printing "Hello World" 2) Calculating the square root and cube root of numbers 3) Converting between binary and decimal numbers and vice versa 4) Checking if a number is prime 5) Summing numbers, swapping values, finding the current date and time 6) Counting words in a string, shutting down/restarting, calculating factorials 7) Checking for palindromes, converting case, finding digit sums, checking for odd/even

Uploaded by

Gopal Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Basic Python Program For Class 11: 1. Hello Word Print ("Hello World")

This document provides examples of 18 basic Python programs including: 1) Printing "Hello World" 2) Calculating the square root and cube root of numbers 3) Converting between binary and decimal numbers and vice versa 4) Checking if a number is prime 5) Summing numbers, swapping values, finding the current date and time 6) Counting words in a string, shutting down/restarting, calculating factorials 7) Checking for palindromes, converting case, finding digit sums, checking for odd/even

Uploaded by

Gopal Tiwari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

BASIC PYTHON PROGRAM

FOR CLASS 11

1. HELLO WORD

Print(“Hello World”)

2. SQUARE ROOT

Number = int(input(“enter a number:


“))
Sqrt = number ** 0.5
Print(“square root:”, sqrt)
3. CUBE ROOT

Def cube_root(x):
Return x**(1/3)
Print(cube_root(27))

4. CONVERT BINARY TO DECIMAL

B_num = list(input(“Enter a binary


number: “))
Value = 0

For i in range(len(b_num)):
Digit = b_num.pop()
If digit == ‘1’:
Value = value + pow(2, i)
Print(“The decimal value of the
number is”, value)

5. CONVERT DECIMAL TO BINARY

Def decimalToBinary(num):
If num > 1:
decimalToBinary(num // 2)
print(num % 2, end=’’)

number = int(input(“Enter any decimal


number: “))
decimalToBinary(number)

6. PRIME NUMBER

Number = int(input(“Enter any


number: “))

If number > 1:
For i in range(2, number):
If (number % i) == 0:
Print(number, “is not a prime
number”)
Break
Else:
Print(number, “is a prime number”)

Else:
Print(number, “is not a prime
number”)

7. PRIME NUMBER 100

Number = 1

While(Number <= 100):


Count = 0
I=2
While(i <= Number//2):
If(Number % i == 0):
Count = count + 1
Break
I=i+1

If (count == 0 and Number != 1):


Print(“ %d” %Number, end = ‘ ‘)
Number = Number + 1

8. COMPARE TO STRING

Str1 = input(“Enter String 1 “)


Str2 = input(“Enter String 2 “)
If(str1 != “”):
If(str1 == str2):
Print(“string is Equal”)
Else:
Print(“string is not Equal”)
Else:
Print(“pls Enter String to check !!!!!!!
1”)

9. SUM OF N NUMBER

Num = int(input(“How many Numbers


sum you Want? : “))

If num < 0:
Print(“Enter a positive number”)
Else:
Sum = 0
While(num > 0):
Sum += num
Num -= 1
Print(“The sum is”,sum)

10.SWAP TWO NUMBER

Number1 = input(‘Enter First Number:


‘)
Number2 = input(‘Enter Second
Number: ‘)
Print(“Value of number1 before
swapping: “, number1)
Print(“Value of number2 before
swapping: “, number2)

Temp = number1
Number1 = number2
Number2 = temp
Print(“-------------------------------------“)
Print(“Value of number1 after
swapping: “, number1)
Print(“Value of number2 after
swapping: “, number2)

11.PRINT DATE
Import datetime
Now = datetime.datetime.now()
Print (“Current date and time : “)
Print (now.strftime(“%Y-%m-%d %H:
%M:%S”))

12.COUNT WORD FROM STRING

Test_string = input(“Enter String :”)

Print (“The original string is : “ +


test_string)
Res = len(test_string.split())
Print (“The number of words in string
are : “ + str(res))

13.SHUTDOWN AND RESTART THE IN


PYTHON

Import os

Shutdown = input(“Do you wish to


shutdown your computer ? (yes / no):
“)

If shutdown == ‘no’:
Exit()
Else:
Os.system(“shutdown /s /t 1”)

14.FACTORIALS IN PYTHON

N = input(“Enter a number: “)
Factorial = 1
If int(n) >= 1:
For i in range (1,int(n)+1):
Factorial = factorial * i
Print(“Factorial of “,n , “ is : “,factorial)

15.PALLINDROME STRING IN
PYTHON
String = input(“Please enter your own
String : “)

If(string == string[:: - 1]):


Print(“This is a Palindrome String”)
Else:
Print(“This is Not a Palindrome
String”)

16.CONVERT LOWERCASE STRING TO


UPPERCASE IN PYTHON

Text = input(“Enter String :”)


Print(“Original String:”)
Print(text)

Print(“\nConverted String:”)
Print(text.upper())

17.FIND THE SUM OF THE DIGIT IN


PYTHON

Def getSum(n):

Sum = 0
For digit in str(n):
Sum += int(digit)
Return sum

N = input(“Enter Number: “)
Print(getSum(n))

18.ODD EVEN PROGRAM IN PYTHON

Num = int(input(“Enter a number: “))


If (num % 2) == 0:
Print(“{0} is Even
number”.format(num))
Else:
Print(“{0} is Odd
number”.format(num))

You might also like