Posts

Showing posts from September, 2019

Chapter 05 - File Handling

Chapter 05 - File Handling Type C: Programming Practice/ Knowledge based Questions 1. Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by a single space. 2. A file sports.dat contains information in following format: Event ~ Participant. Write a function that would read contents from file sports.dat and create a file named Atheletic.dat copying only those records from sports.dat where the event name is "Athletics". 3. A file contains a list of telephone numbers in the following form: Arvind 7258031 Sachin 7259197 The names contain only one word the names and telephone numbers are separated by white spaces. Write a program to read a file and display its contents in two columns. 4. Write a program to count the words 'to' and 'the' present in a text file "Poem.txt". 5.Write a program to count the number of upper-case alphabets ...

Chapter 03 - Working With Functions

Chapter 03 - Working With Functions 1. Write a function that takes amount in dollars and dollar to rupees conversion price; it then returns the amount converted to rupees. Create the function in both void and non-void forms. YOUR CODE HERE 2.Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following input parameters: (a) length of box; (b) width of box; (c) height of box. Test it by writing complete program to invoke it. YOUR CODE HERE 3. Write a program to have following functions: (i) a function that takes a number as argument and calculates cube for it. The function does not return a value. If there is no value passed to the function in function call, the function should calculate cube of 2. def CubeOfNumber(user_input=2): print('Cube of',user_input,'is',user_input**3) user_input=eval(input("Please inse...

Chapter 02 - Python Revision Tour - II

Chapter 02 - Python Revision Tour - II 1. Write a program that prompts for a phone number of 10 digits and two dashes, with dashes after the area code and the next three numbers. For example, 017-555-1212 is a legal input. Display if the phone number entered is valid format or not(i.e., contains just the digits and dash at specific places). phoneNo=input('Please enter a phone number e.g,017-555-1212: ') if len(phoneNo)==12 and (phoneNo[3] and phoneNo[7])=='-': print('The entered phone number is valid') else: print('The entered phone number is invalid') 2.Write a program that should prompt the user to type some sentence(s) followed by "enter". It should then print the original sentence(s) and the following statistics relating to the sentence(s): Number of words Numbe r of characters(including white-space and punctuation) Percentage of character th at are alpha numeric Hints Assume any consecutive sequence of...

Chapter 01 - Python Revision Tour

Python Revision Tour Type C: Programming Practice/ Knowledge based Questions 1. Write a program to print one of the words negative, zero or positive, according to whether variable x is less than zero, zero or greater than zero respectively. user_input=int(input('Please enter a number: ')) if user_input==0: print('Zero') elif user_input 0: print('Positive') 2. Write a program that returns True if the input number is an even number otherwise False. user_input=int(input('Please enter a number: ')) if user_input%2==0: print('True') else: print('False') 3. Write a Python program that calculates and prints the number of seconds in a year. user_input=int(input('Please enter a Year: ')) if user_input%4==0: sec=366*24*60*60 print('Number of seconds in year',user_input,'is',sec,'seconds') else: sec=365*24*60*60 print('Number of seconds in year',user_input,...

Computer Science with Python Class XII (contents)

Computer Science with Python Class XII Python Revision Tour - I Python Revision Tour - II Working with functions Using python libraries File Handling Recursion Idea of Algorithmic Efficiency Data Visualization using Pyplot Data Structure - I: Linear Lists Data Structures - II: Stacks and Queues Computer Networks - I Computer Networks - II MySQL SQL Revision Tour More on SQL Creating a Django based Basic Web Application Interface Python with MySql Society, Law and Ethics