python给信用卡设置默认密码是多少_使用python中的循环配置信用卡编号

我在这个项目中,我必须检查一个信用卡号码是否有效。在这种情况下,我只需要一张8位数的信用卡(我知道那不是事实)。问题就在这里

信用卡号的最后一位是校验位,它可以防止抄写错误,例如一位数的错误或两位数的转换。以下方法用于验证实际信用卡号码,但为了简单起见,我们将对8位数而不是16位数的号码进行描述:• Starting from the rightmost digit, form the sum of every other

digit. For example, if the credit card number is 4358 9795, then you

form the sum 5 + 7 + 8 + 3 = 23.

• Double each of the digits that were not included in the preceding

step. Add all digits of the resulting numbers. For example, with the

number given above, doubling the digits, starting with the

next-to-last one, yields 18 18 10 8. Adding all digits in these values

yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27.

• Add the sums of the two preceding steps. If the last digit of the

result is 0, the number is valid. In our case, 23 + 27 = 50, so the

number is valid.

编写一个实现这个算法的程序。用户应该提供一个8位数的数字,你应该打印出这个数字是否有效。如果无效,则应打印使其有效的校验位值。在

我必须用循环来做和。但是,我不知道如何使用循环。在

这是我的密码# Credit Card Number Check. The last digit of a credit card number is the check digit,

# which protects against transcription errors such as an error in a single digit or

# switching two digits. The following method is used to verify actual credit card

# numbers but, for simplicity, we will describe it for numbers with 8 digits instead

# of 16:

# Starting from the rightmost digit, form the sum of every other digit. For

# example, if the credit card number is 43589795, then you form the sum

# 5 + 7 + 8 + 3 = 23.

# Double each of the digits that were not included in the preceding step. Add # all

# digits of the resulting numbers. For example, with the number given above,

# doubling the digits, starting with the next-to-last one, yields 18 18 10 8. Adding

# all digits in these values yields 1 + 8 + 1 + 8 + 1 + 0 + 8 = 27.

# Add the sums of the two preceding steps. If the last digit of the result is 0, the

# number is valid. In our case, 23 + 27 = 50, so the number is valid.

# Write a program that implements this algorithm. The user should supply an 8-digit

# number, and you should print out whether the number is valid or not. If it is not

# valid, you should print out the value of the check digit that would make the number

# valid.

card_number = int(input("8-digit credit card number: "))

rights = 0

for i in card_number[1::2]:

rights += int(i)

lefts = 0

for i in card_number[::2]:

lefts += int(i)*2%10+int(i)*2/10

print card_number, (rights +lefts)/10

if remaining == 0:

print("Card number is valid")

else:

print("Card number is invalid")

if digit_7 - remaining < 0:

checkDigit = int(digit_7 + (10 - remaining))

print("Check digit should have been:", checkDigit)

else:

checkDigit = int(digit_7 - remaining)

print("Check digit should have been:", checkDigit)

由于信用卡账单费用的计算涉及到多种因素,因此需要先了解各种费用的计算方法,然后根据输入的账单信息进行计算。 以下是信用卡账单费用的计算公式: 1. 本金:账单上未还清的消费金额。 2. 利息:账单日至还款日的利息,计算公式为:本金 * 日利率 * 账单周期天数。 3. 逾期:账单日后未还清的金额。 4. 罚息:逾期金额的罚款,计算公式为:逾期金额 * 日罚息率 * 逾期天数。 5. 手续费:如提现手续费、短信提醒费等。 根据以上公式,我们可以编写如下的Python代码来计算信用卡账单费用: ```python # 输入账单信息 balance = float(input("请输入本月账单上未还清的消费金额:")) interest_rate = float(input("请输入年利率(%):")) / 100 billing_cycle_days = int(input("请输入账单周期天数:")) due_date = int(input("请输入还款日:")) overdue_rate = float(input("请输入日罚息率(%):")) / 100 overdue_days = int(input("请输入逾期天数:")) service_charge = float(input("请输入手续费:")) # 计算账单费用 interest = balance * interest_rate * billing_cycle_days / 365 overdue = balance * overdue_rate * overdue_days total = balance + interest + overdue + service_charge # 输出结果 print("本金:%.2f" % balance) print("利息:%.2f" % interest) print("逾期:%.2f" % overdue) print("罚息:%.2f" % (overdue if overdue_days > 0 else 0)) print("手续费:%.2f" % service_charge) print("总欠款:%.2f" % total) ``` 用户可以根据需要输入账单信息,程序会自动计算账单费用并输出结果。 为了更清楚地了解总欠款每月变化情况,我们可以编写一个循环,每个月更新账单信息并进行计算,然后输出月度账单费用和总欠款金额。 以下是一个简单的示例代码: ```python # 初始账单信息 balance = 5000.0 # 本金 interest_rate = 0.18 / 12 # 月利率 billing_cycle_days = 30 # 账单周期天数 due_date = 25 # 还款日 overdue_rate = 0.05 / 365 # 日罚息率 service_charge = 10.0 # 手续费 # 初始月份为1月 month = 1 total = balance # 循环计算每个月的账单费用和总欠款金额 while total > 0: # 计算账单费用 interest = balance * interest_rate * billing_cycle_days overdue_days = max(0, month * 30 - due_date) overdue = balance * overdue_rate * overdue_days total = balance + interest + overdue + service_charge # 输出结果 print("第%d个月:" % month) print("本金:%.2f" % balance) print("利息:%.2f" % interest) print("逾期:%.2f" % overdue) print("罚息:%.2f" % (overdue if overdue_days > 0 else 0)) print("手续费:%.2f" % service_charge) print("总欠款:%.2f" % total) # 更新账单信息 balance = total month += 1 ``` 该代码会从1月开始循环计算每个月的账单费用和总欠款金额,直到总欠款金额小于等于0为止。每个月的账单费用和总欠款金额会被输出,以便用户了解每个月的还款情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值