为了账号安全,请及时绑定邮箱和手机立即绑定

python 小目标1

Python Day 7

Problem 1:

Given an array of integers, find the sum of its elements.
For example, if the array ar=[1,2,3] , so return 6 .

Solution:

import math

ar=[1, 2, 3, 4, 10, 11]

def simplesumarray(ar):
    return(sum(ar))

simplesumarray(ar)
31

Problem 2:

Given the meal price ( meal), tip percent (tip), and tax percent ( tax) for a meal, find and print the meal’s total integer cost:

Solution:

def solve(meal,tip,tax):
    t=meal+ meal*(tip/100)+ meal*(tax)/100
    return(round(t))

solve(12.00,20,8)
15

[caption id=“attachment_1613” align=“alignnone” width=“750”]

Comfreak / Pixabay[/caption]

Problem 3:

Given an integer,n , perform the following conditional actions:

  • If  is odd, print Weird
  • If  is even and in the inclusive range of 2  to 5, print Not Weird
  • If  is even and in the inclusive range of 6  to 20, print Sort of Weird
  • If  is even and greater than 20, print “Wow”

Solution:

Import math

def classifyn(n):
    if n% 2==1:
        print("Weird")
    elif n%2==0 and n in range(2,6):
        print ("Not weird")
    elif n%2==0 and n in range(6,21):
        print ("Sort of Weird")
    else :
        print("Wow")

classifyn(20)
Sort of Weird

Happy Studying! 🍵

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消