0% found this document useful (0 votes)
10 views

Python Daily Question

The document provides Python and SQL code examples. The Python examples include functions to multiply numbers separated by commas as a string and to square each digit of a number. The SQL examples update all sales employees' salaries to 65000 and retrieve employees joined with their department name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Daily Question

The document provides Python and SQL code examples. The Python examples include functions to multiply numbers separated by commas as a string and to square each digit of a number. The SQL examples update all sales employees' salaries to 65000 and retrieve employees joined with their department name.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PYTHON:

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

# Print and return the product of the numbers.


print (multiply_nums ("2, 3"))
print (multiply_nums ("1, 2, 3, 4"))
print (multiply_nums ("54, 75, 453, 0"))
print (multiply_nums ("10, -2"))

2. Create a function that squares every digit of a number.

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)))

# Print the output


print (square_digits (9119))
print (square_digits (2483))
print (square_digits (3212))

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

SET salary = 65000

WHERE department_id = (SELECT department_id FROM departments WHERE department_name =


'Sales');

Answer 2:

SELECT employees. *, d. department_name

FROM employees

JOIN departments d ON employees.department_id = d.department_id;

Page | 2

You might also like