Python Daily Question
Python Daily Question
1. Given a string of numbers separated by a comma and space, return the product of the numbers.
Examples
multiply_nums ("2, 3") ➞ 6
multiply_nums ("1, 2, 3, 4") ➞ 24
multiply_nums ("54, 75, 453, 0") ➞ 0
multiply_nums ("10, -2") ➞ -20
Answer:
def multiply_nums(nums_str):
nums = nums_str.split(", ")
product = 1 # multiply with any numbers
for num in nums:
product *= int(num)
return product
Examples
square_digits(9119) ➞ 811181
square_digits(2483) ➞ 416649
square_digits(3212) ➞ 9414
Notes
The function receives an integer and must return an integer.
Answer:
def square_digits(num):
return int ('‘. join(str(int(digit)**2) for digit in str(num)))
Page | 1
SQL:
1. Update the salary of all employees in the employee's table who are in the 'Sales' department to
65000.
2. Retrieve all employees from the employee's table along with their department_name from the
department's table, matching on the department_id.
Answer 1:
UPDATE employees
Answer 2:
FROM employees
Page | 2