Basic IT Workshop
Basic IT Workshop
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
else:
print("The Given Character ", ch, "is Not an Alphabet")
Q3. Write a program in python to input a number and display in hex and
octal equivalent.
Q6. Write a program in python to input a year and check is it leap year or
not.
Q7. Write a program in python to input three sides of the triangles and
calculate its area.
import cmath
if weekday == 1 :
print("\nMonday")
elif weekday == 2 :
print("\nTuesday")
elif(weekday == 3) :
print("\nWednesday")
elif(weekday == 4) :
print("\nThursday")
elif(weekday == 5) :
print("\nFriday")
elif(weekday == 6) :
print("\nSaturday")
elif (weekday == 7) :
print("\nSunday")
else :
print("\nPlease enter weekday number between 1-7.")
Q11. Write a program in python to input annual salary and calculate tax :
If income is less than Rs 1,50,000 No tax
If income is Rs 1,50,000 - Rs 3,00,000 10%
If income is Rs 3,00,000 - Rs 5,00,000 20%
More than Rs 5,00,000 30%
amm=int(input("enter ammount"))
if amm<150000:
print("no tax")
elif amm>150000 and amm<=300000:
print("tax is ",amm*.1)
elif amm>300000 and amm<=500000:
print("tax is ",amm*.2)
else:
print("tax is ",amm*.3)
Q13. Write a program in python to input three numbers and check which is
largest.
value = 1
print("Factors of a Given Number {0} are:".format(number))
dnum = 0
i=1
while bnum!=0:
rem = bnum%10
dnum = dnum + (rem*i)
i = i*2
bnum = int(bnum/10)
print("\nEquivalent Decimal Value = ", dnum)
Q2. Write a program in python to input a number in binary and convert into
decimal.
dnum = 0
i=1
while bnum!=0:
rem = bnum%10
dnum = dnum + (rem*i)
i = i*2
bnum = int(bnum/10)
Q3. Write a program in python to input a number and print its multiplication
table.
num = int(input("Show the multiplication table of? "))
for i in range(1,11):
print(num,'x',i,'=',num*i)
Q4. Write a program in python to input two numbers and calculate its GCD.
n = int(input("Enter number"))
sum = 0
# loop from 1 to n
for num in range(1, n + 1, 1):
sum = sum + num
print("Sum of first ", n, "numbers is: ", sum)
average = sum / n
print("Average of ", n, "numbers is: ", average)
Q2. Write a program in python to print sum of all odd numbers from 1 to
100
i=1
sum=0
while i<=100:
if i%2!=0:
sum=sum+i
i=i+1
print ("Sum of odd numbers",sum)
Q3. Write a program in Python to print numbers from 20 to 1.
for i in range(n,0,-1):
print (i)
Q4. Write a program in python that display the power of 2, one per line
21, 22, 23, 24, 25, 26, 27, 28, 29, 210
Q5. A video library rents new videos for ₹ 75 a day, and old movies for ₹ 50
per day. Write a program to calculate the total charge for a customer’s
video rentals. The program should prompt the user for the number of each
type of video and output the total cost.
print('The total cost for',num1,'days new video and',num2,'days old video rent is
',sum)
Q6. Write a program to implement the series
1, 8, 27, 64 , ... ... ... Nth
rows = 5
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(j, end=' ')
print('')
Q10. Write a program to print the pattern
*****
****
***
**
*
rows = 5
for i in range(rows + 1, 0, -1):
# nested reverse loop
for j in range(0, i - 1):
# display star
print("*", end=' ')
print(" ")
Lab-4
Q1.Write a program in python to create an array of 10 elements and print it.
Q2.Write a program in python to transpose a given matrix M = [[1, 2], [4, 5],
[3, 6]].
X = [[1,2],
[4 ,5],
[3 ,6]]
result = [[0,0,0],
[0,0,0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[j][i] = X[i][j]
for r in result:
print(r)
Q3. Write a program in python to print the median of a set of numbers in a
file.
n_num = [1, 2, 3, 4, 5]
n = len(n_num)
n_num.sort()
if n % 2 == 0:
median1 = n_num[n//2]
median2 = n_num[n//2 - 1]
median = (median1 + median2)/2
else:
median = n_num[n//2]
def testprime(n):
if n==1:
print("the given number is a prime number.")
elif n==2:
print("the given number is a even prime number.")
else:
for x in range(2,n):
if n%x==0:
print("the given number is not a prime number.")
break
else:
print("the given number is a prime number.")
break
return n
n=int(input("enter a number to check whether it is prime or not :"))
testprime(n)
Q7. Write a program in python to create a function to check inputted text is
palindrome or not.
def isPalindrome(s):
return s == s[::-1]
s = input("Enter the string ")
ans = isPalindrome(s)
if ans:
print("Yes it is palindrome")
else:
print("No it is not palindrome")
def getSum(n):
sum = 0
for digit in str(n):
sum += int(digit)
return sum
MATLAB
Ex. 1 Write your first Matlab program
a = 3;
b = 5;
c = a+b
Output:
Ex. 2 The meaning of "a = b".In Matlab and in any programming language,
the statement "a = b" does not mean "a equals b". Instead, it prompts the
action of replacing the content of a by the content of b.
a = 3;
b = a;
Output:
a = 3;
b = 9;
c = 2*a+b^2-a*b+b/a-10
Output:
53
a = 3;
a = a+1;
Output:
fprintf('Hello')
Output:
Hello
a = 3;
b = a*a;
c = a*a*a;
d = sqrt(a);
Output:
3 square equals 9
3 cube equals 27
Ex. 7 Arrays
a = [3 6 7];
b = [1 9 4];
c=a+b
Output:
4 15 11
Ex. 8 Extracting an individual element of an array
a = [3 6 7];
b = [1 9 4 5];
c = a(2) + b(4)
Output:
c = 11
Ex. 9 Comment
% a segment of code
A=3;
B = A*A;
C= A+B
Output:
c = 12
+ 9 + 11
Note: The three periods (...) allow continuation to the next line of commands. The
two lines in the above example are essentially one line of "summation1 =
1+3+5+7+9+11".
c1 = 3;
c2 = c1+5;
clear c1
c1
Output:
x = pi;
y = sin(pi/2)
z = exp(-sin(pi/2))
Output:
y=1
z = 0.3679
x = [0:0.1:20];
y = sin(x);
plot(x,y)