零基础Python入门

作为小白新手,选择使用koggle上的引导速成教材入门。
语言学习总是类似的,首先是各种运算的介绍
和其他语言比较不同的有:

符号含义
**指数运算
//取整

接着介绍各种函数
主要使用help和round。
round(num,n)
对于n为负数的情况,和设想的差距较大eg.round(3999,-3)=4000.
对于n为负数的情况,和设想的差距更大

print(round(2.665, 2))
print(round(2.675, 2))

输出为:2.67,2.67
and this is not a bug!

接着介绍条件语言的语法以及函数的定义

def sign(x):
    if x > 0:
        return 1
    elif x < 0:
        return -1
    else:
        return 0

重点注意 ,以及elif
在定义函数后,if, elif, else后都需要**:**
在熟练之后甚至可以有这种写法:

print("Splitting", total_candies, "candy" if total_candies == 1 else "candies")

pass 一般用于占位置。

在 Python 中有时候会看到一个 def 函数:

def sample(n_samples):
    pass

该处的 pass 便是占据一个位置,因为如果定义一个空函数程序会报错,当你没有想好函数的内容是可以用 pass 填充,使程序可以正常运行。

头疼的思考题:
In this problem we’ll be working with a simplified version of blackjack (aka twenty-one). In this version there is one player (who you’ll control) and a dealer. Play proceeds as follows:

The player is dealt two face-up cards. The dealer is dealt one face-up card.
The player may ask to be dealt another card (‘hit’) as many times as they wish. If the sum of their cards exceeds 21, they lose the round immediately.
The dealer then deals additional cards to himself until either:
the sum of the dealer’s cards exceeds 21, in which case the player wins the round
the sum of the dealer’s cards is greater than or equal to 17. If the player’s total is greater than the dealer’s, the player wins. Otherwise, the dealer wins (even in case of a tie).
When calculating the sum of cards, Jack, Queen, and King count for 10. Aces can count as 1 or 11 (when referring to a player’s “total” above, we mean the largest total that can be made without exceeding 21. So e.g. A+8 = 19, A+8+8 = 17)
For this problem, you’ll write a function representing the player’s decision-making strategy in this game.
毫无思路。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值