计算商场折扣

//题解:
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int price = console.nextInt();
        int cost = 0;

        //write your code here......
        //从大到小顺序列出:
    if(price>=5000) cost = (int) (price*0.6);
    else if(price>=2000) cost = (int) (price*0.7);
    else if(price>=500) cost = (int) (price*0.8);
    else if(price>=100) cost = (int) (price*0.9);
    else cost=price;
        
    System.out.println(cost);

    }
}

计算商场折扣_牛客题霸_牛客网 (nowcoder.com)icon-default.png?t=M276https://www.nowcoder.com/practice/cf4dcda7bf974f83afe38af4b14946a7

描述

牛牛商场促销活动:

满100全额打9折;

满500全额打8折;

满2000全额打7折;

满5000全额打6折;

且商场有抹零活动,不足一元的部分不需要付款(类型强制转换)

牛大姨算不清楚自己应该付多少钱,请你帮忙算一下

输入描述:

牛大姨账单钱数(int类型)

输出描述:

参加活动后,牛大姨应付钱数(int类型)

示例1

输入:

654

输出:

523
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 计算商品折扣率的公式是: 折扣率 = (原价 - 现价) / 原价 * 100% 其中,原价为商品的原始价格,现价为商品的现在价格。 以下是一个 Python 函数,可以通过输入原价和现价来计算折扣率: ``` def calculate_discount_rate(original_price, current_price): discount_rate = (original_price - current_price) / original_price * 100 return discount_rate ``` 使用示例: ``` original_price = 100 current_price = 80 discount_rate = calculate_discount_rate(original_price, current_price) print("折扣率为:{:.2f}%".format(discount_rate)) ``` 输出结果为: ``` 折扣率为:20.00% ``` ### 回答2: 计算商品折扣率的方法取决于具体的问题和情况。以下是一种常见的计算方法: 假设原价为P,折扣为D,折扣后的价格为P'。 计算折扣率的公式可以表示为:折扣率(R)= 折扣金额(S)/ 原价(P) 根据这个公式,可以用Python编程来计算商品的折扣率。 代码示例: ```python # 输入原价和折扣金额 P = float(input("请输入商品的原价:")) S = float(input("请输入商品的折扣金额:")) # 计算折扣率 R = S / P # 输出结果 print("商品的折扣率为:", R) ``` 这段代码首先通过input函数获取用户输入的原价和折扣金额。然后将其转换为浮点数类型来进行计算。 接下来,根据折扣率的公式计算折扣率R,并将结果打印输出。 这样,我们就可以用Python来计算商品的折扣率了。希望对您有帮助! ### 回答3: 在Python中计算商品折扣率可以通过以下代码实现: ```python # 输入商品原价和打折后价格 original_price = float(input("请输入商品原价:")) discounted_price = float(input("请输入打折后价格:")) # 计算折扣率 discount_rate = (original_price - discounted_price) / original_price * 100 # 输出折扣率 print("商品的折扣率为:", discount_rate, "%") ``` 首先,我们通过`input`函数分别输入商品的原价和打折后的价格,并使用`float`函数将输入的字符串转换为浮点数。 然后,我们使用下列公式计算折扣率: 折扣率 = (原价 - 打折后价格) / 原价 * 100 最后,我们使用`print`函数输出折扣率。输出时,我们使用字符串拼接的方式将折扣率与百分号连接起来。 例如,如果商品的原价为100元,打折后价格为80元,那么折扣率为:(100 - 80) / 100 * 100 = 20%。程序会输出:"商品的折扣率为: 20.0 %"。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

超翔之逸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值