Saturday, November 9, 2019

Python Basic

1. Hello world program in Python IDLE:-

print("hello world");
sentence="there is a boy";
print(sentence);
print(sentence.replace("boy","girl"));
print(sentence);
print(sentence[1:4]);
print(sentence.upper())
print(sentence.lower())
2. Loop in python :-

n=0
print("this is a program to find sum of first 100 numbers")
for i in range(5):
    i=i+1
    n=n+i
print('the sum is ' + str(n))


4.Example program:-


print('what is your name?')
name=input()
print('hello ' + name)
x=len(name)
print('number of characters in your name is:' + str(len(name)))
print("enter a number")
num1=input()
print('you entered  '+num1)



5. Example 4  

# Store input numbers
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
# Add two numbers
sum = float(num1) + float(num2)
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))