亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

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下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消