Learn the basics of Python 3-Code Challenges:Functions

   1.Coding question 1: Tenth Power

Write a function named tenth_power() that has one parameter named num.
The function should return num raised to the 10th power.

def tenth_power(num):
  return num ** 10

print(tenth_power(1))
# =>1 to the 10th power is 1

print(tenth_power(0))
# =>0 to the 10th power is 0

print(tenth_power(2))
# =>2 to the 10th power is 1024

 2.Coding question 2: Square Root

Write a function named square_root() that has one parameter named num.
Use exponents (**) to return the square root of num.

def square_root(num):
  return num ** 0.5

print(square_root(16))
# =>should print 4

print(square_root(100))
# =>should print 10

 3.Coding question 3: Win Percentage

Create a function called win_percentage() that takes two parameters named wins and losses.
This function should return out the total percentage of games won by a team based on these two numbers.

def win_percentage(wins, losses):
  return wins / (wins + losses) * 100

print(win_percentage(5, 5))
# =>should print 50

print(win_percentage(10, 0))
# =>should print 100

4.Coding question 4: Average

Write a function named average() that has two parameters named num1 and num2.
The function should return the average of these two numbers.

def average(num1, num2):
  return (num1 + num2)/2

print(average(1, 100))
# =>The average of 1 and 100 is 50.5

print(average(1, -1))
# =>The average of 1 and -1 is 0

 5.Coding question 5: Remainder

Write a function named remainder() that has two parameters named num1 and num2.
The function should return the remainder of twice num1 divided by half of num2.

def remainder(num1, num2):
  return (num1 * 2) % (num2 / 2)

print(remainder(15, 14))
# =>should print 2

print(remainder(9, 6))
# =>should print 0

Learn the basics of Python 3-Chapter 5:Functions

Learn the basics of Python 3-Code Challenges:Functions(Advanced)

  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

皮猴的路数

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值