1. Python Program to Swap Two Variables. Program: A=Int(Input("Enter the First Number
1. Python program to swap two variables. Program: a=int(input("Enter the first number: ")) b=int(input("Enter the first number: ")) print("Nos. before swap ",a,"and",b) a,b=b,a print("Nos. after swap ",a,"and",b) Output: Enter the first number: 10 Enter the first number: 20 Nos. before swap 10 and 20 Nos. after swap 20 and 10 2. Python program to generate a random number. Program: import random print("Generated random number is ",random.randint(10,20)) Output: Generated random number is 16 3. Python program to convert Kilometers to Miles. Program: a=int(input("Enter the number of Kilometers: ")) print("Miles : ",a*5/8) Output: Enter the number of Kilometers: 13 Miles : 8.125 4. Python program to perform selection sort in ascending order. Program: def printArray(arr): print (' '.join(str(i) for i in arr)) def selectionsort(arr): N = len(arr) for i in range(0, N): small = arr[i] pos = i for j in range(i + 1, N): if arr[j] < small: small = arr[j] pos = j temp = arr[pos] arr[pos] = arr[i] arr[i] = temp print ("After pass ", str(i), " :") printArray(arr) arr = [10, 7, 3, 1, 9, 7, 4, 3] print ("Initial Array :") printArray(arr) selectionsort(arr) Output: Initial Array : 10 7 3 1 9 7 4 3 After pass 0 : 1 7 3 10 9 7 4 3 After pass 1 : 1 3 7 10 9 7 4 3 After pass 2 : 1 3 3 10 9 7 4 7 After pass 3 : 1 3 3 4 9 7 10 7 After pass 4 : 1 3 3 4 7 9 10 7 After pass 5 : 1 3 3 4 7 7 10 9 After pass 6 : 1 3 3 4 7 7 9 10 After pass 7 : 1 3 3 4 7 7 9 10 5.
[Show full text]