網站首頁 編程語言 正文
此為平時日常老師所布置的作業。
1.?編寫程序實現:
(1)寄送包裹小于5kg
每公斤0.5元,大于等于5kg,超出5公斤部分,按照每公斤0.8元計算,輸入重量,輸出應付金額。
程序粘貼:
weight=eval(input("請輸入重量:")) if weight<5.0: money=weight*0.5 else: money=5.0*0.5+(weight-5.0)*0.8 print("應付金額為:",money)
結果截圖粘貼:
(2)郵寄包裹重量
小于5公斤,每公斤0.5元;大于等于5公斤小于10公斤,超出5公斤部分按照每公斤0.8元計算;大于等于10公斤小于20公斤,超出10公斤部分按照1元計算;大于等于20公斤,每公斤按照1.2元計算,輸入重量輸出應付金額。
程序粘貼:
weight=eval(input("請輸入重量:")) if weight<5.0: money=weight*0.5 elif 5
結果截圖粘貼:
(3)用if嵌套完成
第(2)題中的問題
程序粘貼:
weight=eval(input("輸入包裹重量:")) if weight<20: if 10<=weight<20: money = 10 * 0.8 + (weight - 10) * 1 elif 5<=weight<10: money = 5 * 0.5 + (weight - 5) * 0.8 else: money=weight*0.5 money=weight*1.2 print("應付金額為:",money)
結果截圖粘貼:
原文鏈接:https://blog.csdn.net/qq_51191109/article/details/123051305
相關推薦
- 2022-06-22 React表單容器的通用解決方案_React
- 2021-12-17 Windows下Flutter+Idea環境搭建及配置_Android
- 2023-02-09 Go語言高效編程的3個技巧總結_Golang
- 2022-09-09 Go語言提升開發效率的語法糖技巧分享_Golang
- 2023-06-19 Python進行文件處理的示例詳解_python
- 2022-05-13 C++ 使用ffmpeg實現rtsp取流
- 2024-03-05 git創建分支
- 2022-12-14 Jetpack?Compose?雙指拖拽實現詳解_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支