如何创建一个while循环,询问用户是否要继续,如果没有,它会破坏?

时间:2017-10-08 02:11:46

标签: python-3.x

该程序将询问用户单价和数量。然后它将单位价格乘以数量。如果数量大于10,则可享受5%的折扣。如果数量大于100,则可享受10%的折扣。

def bmth(unit, quan):
    def computeN(unit, quan):
        z = unit * quan
        print(z)

    if 10 <= quan < 99:
        ordercost = unit * quan
        discfive = ordercost * .05
        v = ordercost - discfive
        print('Your original price was ', ordercost)
        print('You Saved', discfive, 'off')
        print('Your new price is now ', v)
    elif quan >= 100:
        ordercost2 = unit * quan
        discten = ordercost2 * .10
        n = ordercost2 - discten
        print('Your original price was ', ordercost2)
        print('You save ', discten, 'off')
        print('Your new price is now ', n)
    else:
        computeN(unit, quan)

while True:
    unit = float(input('Enter the Unit price: '))
    quan = int(input('Enter your items: '))
    onelasttime = input('Do you wish to continue? Y or N: ')
    Y = bmth(unit, quan)
    if onelasttime:
        input(Y)
    elif onelasttime:
        input(N)
    break

1 个答案:

答案 0 :(得分:0)

修正了int i = 0; //for each item in a list of skills... IEnumerator<Skill> list = SkillList.getSkillList(); Transform skillListParent = GuiManager.instance.skillPanel.transform; while(list.MoveNext()) { Skill sk = list.Current; //create a prefab clone... GameObject go = Main.Instantiate(PrefabManager.instance.SKILL_LISTITEM, skillListParent) as GameObject; //set its position... go.transform.localPosition = new Vector3(5, i * -110 -5, 5); //add a button event or other data (some lines omitted)... Transform t1 = go.transform.FindChild("BuyOne"); t1.GetComponent<Button>().onClick.AddListener(delegate { doBuySkill(sk); }); t1.GetChild(0).GetComponent<Text>().text = Main.AsCurrency(sk.getCost(1)) + " pts"; //track how many... i++; } //update rect transform ((RectTransform)skillListParent).SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (i * 110 + 10)); 循环:

while

观察:

  1. while True: unit = float(input('Enter the Unit price: ')) quan = int(input('Enter your items: ')) not_continue = input('Do you wish to continue? Y or N: ') is 'N' bmth(unit, quan) if not_continue: break 是一个字符串,因此onelasttimetruthy并评估为'N'
  2. True未返回,因此bmth始终为Y = bmth(unit, quan)
  3. 如果None不在break,那么if将在第一次循环时中断。