Beginner's Python Program
# First program in python
print("hello world")
print('hello world')
# Single line comments
''' This multiple line comments '''
# PRACTICE SET QUESTION
''' question 1
write program to print poem twinkle twinkle little star
'''
print('''Twinkle twinkle little star,
How I Wonder ehat you are!
up above the world so high,
like a diamond in sky''')
# PRACTICE SET QUESTION
''' question 2
Install an external module and use it to perform an operation of your interest
'''
# PRACTICE SET QUESTION
''' question 3
write a python program to print the content of a directory using os module.search online for the function which does that
'''
import os
print(os.listdir())
# PRACTICE SET QUESTION
''' question 4
label the program written in problem 4 with comments
-->> use button ---->>> ctrl+/'''
# chapter 2 variable in python
a = "himanshu"
x = ''' hello himanshu'''
y = '''next line variable
hello himanshu shekhar'''
# 1a_ = 4687 <<--- this not valid variable
b = 55
c = 55.12
d = False
e = None
# printing variable
print(a)
print(x)
print(y)
print(b)
print(c)
# printing the type of variable
print(type(a))
print(type(x))
print(type(y))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
# operators example
''' arithmetic operator'''
print("result of 3+4 is",3+4)
print("result of 4-3 is",4-3)
print("result of 3*2 is",3*2)
print("result of 3/2 is ",3/2)
'''assignment operators'''
a = 32
a += 2
print(a)
b = 4
b *= 8
print(b)
'''comparison operator'''
# b = (16<7)
# b = (16>4)
# b = (16==8)
# b = (16<=8)
# b = (16>=2)
b = (16!=6)
print(b)
'''logical operator'''
bool1 = True
bool2 = False
print("the value of bool1 and bool2 is ",(bool1 and bool2))
print("the value of bool1 or bool2 is ",(bool1 or bool2))
print("the value of bool1 not bool2 is ",(not bool2))
'''type casting---->> it convert one data to another datatype'''
a = "25"
a =int(a)
print(type(a))
print(a+5)
# input() functon -->> it take input from the user keyboard as a string
a = input(" please enter your name: ")
# a = int(a) --->>> convert a to integer if possible
print(a)
print(type(a))
# chapter 2 practice set (variable)
''' Question 1
WAP in python to add two number
'''
a = 85
b = 65
print(a+b)
'''Question 2
WAP in python to find remainder when a number is divided by z
'''
a = 25#(input("enter the first number:"))
b = 5 #(input("enter the second number"))
result = a % b # <<---- it gives remainder
print(a/b) # <<<--- it gives quotients
print(result)
'''Question 3
use comparision operators to find out whether a given variable a is greater than 'b' or not take a=43 and b=80
'''
# a = 34
# b = 80
# a>b ---- this code is used in cmd directly
'''Question 4
WAP in python to find average of two number entered by user
'''
a = input(" enter the first number")
a = int(a)
b = input(" enter the second number")
b = int(b)
average = (a+b)/2
print("average of two number is ",average)
'''Question 5
WAP in python to calculate the square root of a number
'''
a = int(input("enter the number"))
print(a*a)
No comments:
Post a Comment