跳至主要內容

01-变量专项练习

AI悦创原创Python 私教练习题【基础】Python 基础练习题大约 3 分钟...约 778 字

1. 交换果汁

假如你有两个小孩,哥哥叫:Austin,弟弟叫:Jaden。

Austin 想喝果汁,Jaden 想喝可乐哥哥和弟弟都有专属的杯子,不喜欢用对方的杯子。

家中仅剩一杯果汁、一杯可乐,你不小心把哥哥的杯子装了可乐,弟弟的杯子装了果汁。

问:如何交换哥哥与弟弟杯中的果汁?

zh

Suppose you have two children, the elder brother is named Austin, and the younger brother is named Jaden. Austin wants to drink juice, and Jaden wants to drink cola. Both brothers have their own exclusive cups and don't like to use each other's cups. There is only one cup of juice and one cup of cola left at home, and you accidentally filled the elder brother's cup with cola and the younger brother's cup with juice. How can you swap the juice in the brothers' cups?

样例代码
Austin = "Coke"  # 该赋值可以理解为倒果汁的过程
Jaden = "juice"  # 该赋值可以理解为倒果汁的过程
print("Austin", Austin)
print("Jaden", Jaden)
# 待补充代码
print("Austin", Austin)
print("Jaden", Jaden)

警告!!!

不要出现如下方法!!!
Austin = "Coke"
Jaden = "juice"
print("Austin", Austin)
print("Jaden", Jaden)
# 待补充代码
print("Austin", Jaden)
print("Jaden", Austin)

2. 创建变量并输出

  1. 输出效果:
Austin Jaden Alex Cava
  1. 输出效果如下:
Austin$Jaden$Alex$Cava%

悦创金句

程序员就是连接人与机器之间的桥梁——AI悦创

欢迎关注我公众号:AI悦创,有更多更好玩的等你发现!

公众号:AI悦创【二维码】

AI悦创·编程一对一

AI悦创·推出辅导班啦,包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发」,全部都是一对一教学:一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然,还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线,随时响应!微信:Jiabcdefh

C++ 信息奥赛题解,长期更新!长期招收一对一中小学信息奥赛集训,莆田、厦门地区有机会线下上门,其他地区线上。微信:Jiabcdefh

方法一:QQopen in new window

方法二:微信:Jiabcdefh

上次编辑于:
贡献者: AndersonHJB,AI悦创
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度