Python Assingment - PY
Python Assingment - PY
/usr/bin/env python
# coding: utf-8
# # 1. Take a variable ‘age’ which is of positive value and check
the following:
# a. If age is less than 10, print “Children”.
# b. If age is more than 60 , print ‘senior citizens’
# c. If it is in between 10 and 60, print ‘normal citizen’
#
# In[1]:
age= int(input("Enter your Age : "))
if age<10:
print("Children")
elif age>60:
print("Senior Citizen")
else:
print("Normal Citizen")
# # 2. Find the final train ticket price with the following
conditions.
# a. If male and sr.citizen, 70% of fare is applicable
# b. If female and sr.citizen, 50% of fare is applicable.
# c. If female and normal citizen, 70% of fare is applicable
# d. If male and normal citizen, 100% of fare is applicable
#
# In[2]:
import pandas as pd
gender = str(input("Male or Female : "))
age1 = int(input("Enter your age : "))
if gender =='Male' and age1>=60:
print("70% of fare is applicable")
elif gender=='Female' and age1>=60:
print("50% of fare is applicable")
elif gender== 'Male' and age1<60:
print("100% of fare is applicable")
if gender == 'Female' or age1<60:
print("70% of fare is applicable")
# # 3. Check whether the given number is positive and divisible by 5
or not
# In[3]:
number = float(input(" Please Enter any Positive Integer : "))
if number % 5 == 0:
print("Given Number {0} is Divisible by 5 ".format(number))
else:
print("Given Number {0} is Not Divisible by 5 ".format(number))
# # 4.
# A) list1=[1,5.5,(10+20j),’data science’].. Print default functions
and parameters exists in list1.
# B) How do we create a sequence of numbers in Python.
# C) Read the input from keyboard and print a sequence of numbers
up to that number
#
#
# In[7]:
list1=[1,5.5,(10+20j),'data science']
def func(list1):
print(list1)
func(list1)
# In[8]:
# B) How do we create a sequence of numbers in Python.
for i in range(10):
print(i)
# In[9]:
# C) Read the input from keyboard and print a sequence of numbers up to
that number
for i in range(11):
print(i)
# # 5. Create 2 lists.. one list contains 10 numbers
(list1=[0,1,2,3....9]) and other
# list contains words of those 10 numbers
(list2=['zero','one','two',.... ,'nine']).
# Create a dictionary such that list2 are keys and list 1 are
values..
# In[10]:
list1 = [0,1,2,3,4,5,6,7,8,9]
list2 = ['zero' , 'one', 'two', 'three' , 'four','five', 'six','seven',
'eight', 'nine']
print(dict(zip(list2, list1)))
# # 6. Consider a list1 [3,4,5,6,7,8]. Create a new list2 such that
Add 10 to the even number and multiply with 5 if it is odd number in the
list1..
# In[11]:
import numpy as pd
list2 = [num+10 if (num%2)==0 else num*5 for num in list1]
list2