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
  • 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...

  • 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...

  • Create a Python list (use first three letters of your name followed by the letter L...

    Create a Python list (use first three letters of your name followed by the letter L as the name of the list.) with the following data: 10, 20.0, 50.00, 7000, 7500, 7700, 7800, 8000, 9000, ‘python’. Display the entire list with an appropriate message. Display the 4th element in the list with an appropriate message. Display the first 3 values of the list only. Display all the values starting from the sixth element to the end of the list. Change...

  • 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....

  • Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description:...

    Language: Python Topic: Dictionaries Function name: catch_flight Parameters: dictionary, tuple containing two strings Returns: dictionary Description: You’ve been stuck in NYC for around 8 months all by yourself because you haven’t been able to find a good time to fly home. You’re willing to go to any city but want to see how many flights to each location fit your budget. You’re given a dictionary that has city names (strings) as the keys and a list of prices (list) and...

  • 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...

  • 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...

  • Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called...

    Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows: 1.) Max, Min, Standard_Deviation, Mean a.) Each of these should take a list as a parameter and return the calculated value 2.) Bubble a.) This should take a list as a parameter and return the sorted list 3.) Median a.) This should take a list as a...

  • 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...

  • 5. What does this error refer to?Traceback (most recent call last): File "program.py", line 2, in...

    5. What does this error refer to?Traceback (most recent call last): File "program.py", line 2, in times[2] = 10TypeError: 'tuple' object does not support item assignment * 6. Like most other builtin Python data types, tuples can be compared using the standard comparison operators. True or False? * True False 7. The easiest way to think about sets is that they are like dictionaries without values; that is, the keys in a dictionary are a set. True or False? *...

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