Skip to content

Latest commit

 

History

History
215 lines (185 loc) · 8.1 KB

questions.md

File metadata and controls

215 lines (185 loc) · 8.1 KB

Questions

What is programming
1. Write a short description what a programming is
     - A program is a set of instruction that can executed by a computer
2. List down some of the importance of python programming language
     - To develop a desktop application, server-side programming, data analysis, ML, etc
3. What version of python are you currently using? 3.9.2
4. What code editor are you using? VScode 
5. What is the python interactive shell?
6. How do you open the python interactive shell and how do you close it?
7. What is the extension of the python script file? 
Functions
  1. What is a function? 
    - A block of code that allows you to perform a certain task
  2. Functions can be divided into two: builtin functions and custom functions
  3. Write at least 10 builtin functions and perform some task using the function
Comments
1 What is the use of a comment in programming
  - To make the code readable, maintainable, reusable, to leave remark
2. Write a single line python comment
3. Write a multiline python comment
Data types
1. List all the data types you know
2. Give one example for each data types
Variables
- Declare a variable of all data types
- Check the type of your variables using type
Operations
What is an assignment operator? 
What are the Python Arithmetic operators?
What are the Python comparison operators > < >= <= == !==,
What are the Python logical operators ? and, or, not
Type casting
```sh
num_int = 10
num_str = '5'
gravity = 9.81
```
1. Change the value at num_int to float
2. Change the value at num_int to string
3. Change the value at gravity to integer
4. Change the value at gravity  to string
5. Change the num_str to to int
6. Change the num_str to float
Getting user input

Write a small script that can calculate the age of a person. The program asks the user to enter birth year and the current year.

Enter your birth year: 1950
Enter the current year: 2020
You are 70 years old.

Write a small script that can calculate the weight of an object on Earth. The program asks user to enter mass and calculate the weight.

Enter your weight: 100
Your weight is 98.1 N.
Strings
- Concatenate the string 'Python', 'For','Everyone' to a single string, 'Python for Everyone'
- Concatenate the string 'Coding', 'For', 'All' to a single string, 'Coding For All'
- Declare a variable name company and assign it to an initial value "Coding For All".
- Print company using print()
- Print the length of the company string using len() method and print()
- Change all the string to capital letters using upper() method
- Change all the string to lowercase letters using lower() method
- Use capitalize(),title(), swapcase() methods to format the value stored in the variable name company
- Slice out the first word of the company string
- Check if the string contains a word Coding using the method index or other methods.
- Replace the word coding in the string 'Coding For All' to Python using replace or other methods.
- Change Python for Everyone to Python for All using the replace method or other methods
- Split the string 'Coding For All' at the space using split() method
- "Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon" split the string at the comma
- What is character at index 10 in "Coding For All"
- Create an acronym or an abbreviation for the name 'Python For Everyone'
- Create an acronym or an abbreviation for the name 'Coding For All'
- Use index to determine the position of the first occurrence of C in Coding For All
- Use index to determine the position of the first occurrence of F in Coding For All
- Use rfind to determine the position of the last occurrence of l in Coding For All People.
- Use index or find to find the position of the first occurrence of the word because in the following sentence:'You cannot end a sentence with because because because is a conjunction'
- Use rindex to find the position of the last occurrence of the word because in the following sentence:'You cannot end a sentence with because because because is a conjunction'
- Slice out the phase because because because in the following sentence:'You cannot end a sentence with because because because is a conjunction'
- Use search to find the position of the first occurrence of the word because in the following sentence:'You cannot end a sentence with because because because is a conjunction'
- Slice out the phase because because because in the following sentence:'You cannot end a sentence with because because because is a conjunction'
- Use trim() to remove if there is trailing whitespace at the beginning and the end of a string.E.g " Coding For All ".
- Use startswith() method with the string Coding For All make the result true
- Use endswith() method with the string Python for Everyone make the result true

Conditionals
- Get user input using input(“Enter your age:”). If the user is 18 or older, give feedback: You are old enough to drive but if not 18 give feedback to wait for the years he supposed to wait for.
  
  ```sh
  Enter your age: 30
  You are old enough to drive.
  Enter your age:15
  You are left with 3 years to drive.
  ```
- Compare the values of myAge and yourAge using if … else. Based on the comparison log to console who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.

    Enter your age: 30
    You are 5 years older than me.

- If a is greater than b return a is greater than b else a is less than b. Output: sh let a = 4; let b = 3; 4 is greater than 3

    Write a code which give grade students according to theirs scores:
        80-100, A
        70-89, B
        60-69, C
        50-59, D
        0 -49, F

- Check if the season is Autumn, Winter, Spring, or Summer. If the user input is:

    September, October or November, the season is Autumn.
    December, January or February, the season is Winter.
    March, April or May, the season is Spring
    June, July or August, the season is Summer
Lists
1. Declare an empty list
2. Declare a list with more than 5 number of items
3. Find the length of your list
4. Get the first item, the middle item and the last item of the list
5. Declare a list called mixed_data_types, put different data types in your array and the array size should be greater than 5
6. Declare a list variable name it_companies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon.
7. Print the list using print()
8. Print the number of companies in the list
9. Print the first, middle and last company
10. Print out each company
11. Print out the starting letter of each company name
12. Change companies names to uppercase and print them out
13. Print the list like a sentence: Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon are big IT companies.
14. Check if a certain company exists in the it_companies list. If it exist return the company else return a company is _not found.
15. Filter out companies which have more than one 'o' without the filter method
16. Sort the array using sort() method
17. Sort the array using sorted builtin function
18. Reverse the array using the reverse method
19. Reverse the array without reverse method
20. Reverse the array using method
21. Slice out the first 3 companies from the list
22. Slice out the last 3 companies from the list
23. Slice out the middle IT company or companies from the list
24. Add CISCO to the companies list
25. Add SalesForce and DEL to the companies list at once
26. Insert Intel next IBM in the companies list
27. Remove the first IT company from the array
28. Remove the middle IT company or companies from the list
29. Remove the last IT company from the list
30. Remove all IT companies