Posts

Showing posts from March, 2023

Program 8

Image
 8.Write a Python program to plot pie chart using labels of brands of cars 'AUDI', 'BMW', 'FORD', 'TESLA', 'JAGUAR', 'MERCEDES' and sales of the cars. A Pie Chart is a circular statistical plot that can display only one series of data. The area of the  chart is the total percentage of the given data. The area of slices of the pie represents the  percentage of the parts of the data. The slices of pie are called wedges. The area of the wedge  is determined by the length of the arc of the wedge. The area of a wedge represents the relative  percentage of that part with respect to whole data. Pie charts are commonly used in business  presentations like sales, operations, survey results, resources, etc as they provide a quick  summary. Creating Pie Chart Matplotlib API has pie() function in its pyplot module which create a pie chart representing the  data in an array.  Syntax: matplotlib.pyplot.pie(data, explode=None, labels=None, colors=None, ...

Program 7

Image
 7.Write a Python program to plot bar graph using labels of languages ‘C', 'C++',  'Java', 'Python', 'PHP' and students’ marks scored in above languages. matplotlib.pyplot is a collection of command style functions that make matplotlib work like  MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a  plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc.  In matplotlib.pyplot various states are preserved across function calls, so that it keeps track of  things like the current figure and plotting area, and the plotting functions are directed to the  current axes. A bar plot or bar chart is a graph that represents the category of data with rectangular bars  with lengths and heights that is proportional to the values which they represent. The bar plots  can be plotted horizontally or vertically. A bar chart describes the comparisons between the  discrete ...

Program 6

 6. Write a Python program to create an array of 5 integers and display an array? from array import * array_num = array('i', [1,3,5,7,9]) for i in array_num:   print(i) print("Access first three items individually") print(array_num[0]) print(array_num[1]) print(array_num[2]) OUTPUT 1 3 5 7 9 Access first three items individually 1 3 5

Program 5

 5. Write a program to count a number of vowels in a string? Steps: 1. User must enter a string and store it in a variable. 2. The count variable is initialized to zero. 3. The for loop is used to traverse through the characters in the string. 4. An if statement checks if the character is a vowel or not. 5. The count is incremented each time a vowel is encountered. 6. The total count of vowels in the string is printed string=input("Enter string:") vowels=0 for i in string:        if(i=='a' or i=='e' or i=='i' or i=='o' or i=='u' or i=='A' or i=='E' or i=='I' or i=='O' or i=='U'):              vowels=vowels+1 print("Numbers of vowels are:") print(vowels) OUTPUT Enter string: bgsit is a good college Numbers of vowels 

Program 4

 4. Write a Python program to find length of string and to convert upper to lower case of a string The function len() returns the length of a given string. The lower() converts the given string in  into lowercase and returns the string. The upper()converts the given string in into uppercase  and returns the string. # User inputs the string and it gets stored in variable str str = input("Enter a string: ") print("Length of the input string is:", len(str)) str = input("Enter Upper Case string: ") print(str.lower()) str = input("Enter Lower Case string: ") print(str.upper()) OUTPUT: Enter a string: Computer science Length of the input string is: 16 Enter Upper Case string: BGSIT bgsit Enter Lower Case string: adichuchanagiri ADICHUCHANAGIRI

Program 3

 3. Write a Python program to check whether a given number is prime or not A positive integer greater than 1 which has no other factors except 1 and the number itself is  called a prime number. 2, 3, 5, 7 etc. are prime numbers as they do not have any other factors.  But 6 is not prime (it is composite) since, 2 x 3 = 6. num = int(input("Enter a number: ")) flag = False if num > 1:      for i in range(2, num):           if (num % i) == 0:               flag = True               break if flag:     print(num, "is not a prime number") else:     print(num, "is a prime number") OUTPUT Enter a number: 123 123 is not a prime number Enter a number: 13 13 is a prime number

Program 2

 2. Write a Python program to convert temperature in Celsius to Fahrenheit. In the program below, we take a temperature in degree Celsius and convert it into degree  Fahrenheit. They are related by the formula Fahrenheit = Celsius * 1.8 + 32 Program 2: #Python Program to convert temperature in Celsius to fahrenheit #change this value for a different result print("Enter Temperature in Celsius: ") celsius = int(input()) fahrenheit = (celsius * 1.8) + 32 print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit)) OUTPUT Enter Temperature in Celsicus:  167 167.0 degree Celsius is equal to 332.6 degree Fahrenheit

Program 1

 1. Write a Python program to find sum and average of two numbers Program 1: In this program, you will learn to add two numbers and display it using print() function. To understand this progam, you should have the knowledge of the following Python  programming topics:  Python Basic Input and Output  Python Data Types  Python Operators # Python program to find average of two numbers  # first number num1 = 10 num2 = 20 sum=num1+num2 print('sum of numbers = %d' %sum) avg = (num1+num2)/2 print('The average of numbers = %0.2f' %avg) OUTPUT sum of numbers = 30 The average of numbers = 15.00