Question

Questions 1. How to create a comment in python? 2. The way to obtain user input...

Questions

1. How to create a comment in python?
2. The way to obtain user input from command line
3. List standard mathematical operators in python and explain them
4. List comparison operators in python
5. Explain while loop. Give example
6. Explain for loop. Give example
7. How to create infinite loop? And how to stop it?
8. Explain a built-in function ‘range’ for ‘for’ loop
9. Explain break statement
10. Explain continue statement
11. Explain pass statement
12. What is the string?
13. String literals (how to create a string)
14. Name at least 4 string methods
15. What is the List?
16. Name at least 4 list methods
17. Name two ways to delete all elements of the list
18. Name the ways to add elements to list
19. What is the tuple?
20. How to create a tuple with one element?
21. How to Access Values in Tuples
22. How to Update Tuples
23. How to Remove Tuple Elements and Tuples
24. How to find smallest number from the tuple of numbers?
25. How can we sort dictionary keys alphabetically? Show examples
26. Name operations that change a dictionary object in-place(by key). Give example
27. Name operations that checks an existence of some key in dictionary
28. How to Remove Dictionary Elements
29. Explain how two dictionaries are compared
30. What data types can be used as key for dictionaries?
31. What is the function?
32. Why use functions?
33. Create a function that return sum of two input arguments.
34. Create a function that checks if the given number is positive or not.
35. Create a function that calculates square of given input value.
36. What is the module in python?
37. How to create a module?
38. The process of importing a module requires a process called a path search. Where python will make a search?
39. How to ‘bring in’ a module to program?
40. List at least 4 methods from Math module and explain them
41. Explain random.seed() method
42. Explain random.randrange(start, stop, step) method
43. Explain random.choice(seq) method
44. Explain random.shuffle(seq) method
45. Explain random.sample(seq,n) method
46. Explain random.random() method
47. How to open a file with name ‘test.txt’ to read from file?
48. Explain the access mode ‘w’ for opening file
49. Explain the access mode ‘a’ for opening file
50. Explain the access mode ‘r’ for opening file
51. Explain the access mode ‘r+’ for opening file
52. What is the default access mode and explain it
53. What kind of built in methods of file object can be used to get (input) information from file?
54. What kind of built in methods of file object can be used to store (output) information to file?
55. Explain methods tell() and seek() of file object
56. Standard files in python
57. What is the ‘pickling’?
58. What is ‘unpickling’?
59. What is exception?
60. Explain try-except statement
61. else clause in try-except statement
62. finally clause in try-except statement
63. Explain try-finally statement
64. The usage of regular expressions
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1:-How to create a comment in Python?
ans:-
1)Single Line Comment-
   '#' is used to create a single line comment in python.
   e.g:-
       # This is Single Line Comment. Anything written here is ignored by Python
       print("Hello Students!")
2) Multi-Line Comment:-
   We can add a multiline comment in python code using triple quotes
   e.g:-
       '''
           This is a Multi-Line Comment.
           Anything written here is ignored by Python
       '''
       print("Hello Students!")

Q2:-way to obtain user input from command line
ans:-
   To take input from the user from command line we make use of a built-in function input().
   e.g1
       #accept command line input
       num=input();
       print(num);
Q3:-List standard mathematical operators in python and explain them
ans:-

   i)Addition(+):
       adds two operands                      
       Syntax:-a + b
   ii)Subtraction(-):
       subtracts two operands              
       Syntax:-a - b
   iii)Multiplication(*):
       multiplies two operands      
       Syntax:-a * b
   iv)Division -float(/):
       divides the first operand by the second  
       Syntax:-a / b
   v)Division-floor(//):
       divides the first operand by the second  
       Syntax:-a // b
   vi)Modulus(%):
       returns the remainder when first operand is divided by the second  
       Syntax:-a % b

Q5:- Explain while loop. Give example
ans:-
   Repeats a block of statements while a given condition is TRUE.
   Syntax:-
       while (Condition):
       #block of statements
   e.g
       #Program to find factorial using while
       print('Enter num to find factorial:-');
       num=input();
       i=1
       fact=1;
       while i < num:
           i=i+1;
           fact=fact*i
       print('Factorial:-');
       print(fact);
  
  

Add a comment
Know the answer?
Add Answer to:
Questions 1. How to create a comment in python? 2. The way to obtain user input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a...

    python #Ignore line 2, it is just there to align with zybooks requirements print("5") #Create a list with the following numbers and assign it to a variable name: 1,2,3,4,5,6 #Convert the list to a tuple and assign it to a variable name (dirrerent from the list's name) #Try the following and press the run program button to which ones work and which ones cause errors #If a statement causes an error, use a # to comment it out #Add the...

  • In python Count the frequency of each word in a text file. Let the user choose...

    In python Count the frequency of each word in a text file. Let the user choose a filename to read. 1. The program will count the frequency with which each word appears in the text. 2. Words which are the spelled the same but differ by case will be combined. 3. Punctuation should be removed 4. If the file does not exist, use a ‘try-execption’ block to handle the error 5. Output will list the words alphabetically, with the word...

  • Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write...

    Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

  • 1. Pleae write the following code in Python 3. Also, please show all the outputs. ....

    1. Pleae write the following code in Python 3. Also, please show all the outputs. . Write a simple Rectangle class. It should do the following: Accepts length and width as parameters when creating a new instance Has a perimeter method that returns the perimeter of the rectangle Has an area method that returns the area of the rectangle Don't worry about coordinates or negative values, etc. Python provides several modules to allow you to easily extend some of the...

  • 1) We have returned to our ingredients dictionary. We want to display the ingredients in alphabetical...

    1) We have returned to our ingredients dictionary. We want to display the ingredients in alphabetical order. Dictionaries cannot be sorted, so we need to use the items method to convert the dictionary into a list of tuples. Then we can sort that new list of tuples, then display the ingredients. Use items and list to convert ingredients into a list of tuples. Sort the new list, called ingred_list Write a for loop which goes through each tuple in ingred_list....

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • True or False: Python programs require two or more modules. 1. 2. The keyword while means the same thing as While in Python. 3. In Python, _MyVar15 is a valid variable name. 4. To make your progr...

    True or False: Python programs require two or more modules. 1. 2. The keyword while means the same thing as While in Python. 3. In Python, _MyVar15 is a valid variable name. 4. To make your program more secure, use obscure variable names such as xz14dEE 5. Indenting code that should be executed when an if statement evaluates as true makes your program easier to read, but the indentation is not necessary. 6. A dictionary object contains zero or more...

  • Help needed related python task ! Thanx again How you're doing it • Write a function...

    Help needed related python task ! Thanx again How you're doing it • Write a function write_to_file() that accepts a tuple to be added to the end of a file o Open the file for appending (name your file 'student_info.txt') o Write the tuple on one line (include any newline characters necessary) o Close the file • Write a function get_student_info() that o Accepts an argument for a student name o Prompts the user to input as many test scores...

  • CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1....

    CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT