How do I show a suffix to user input in Python?

2024/10/11 14:23:19

I want a percentage sign to display after the users enters their number. Thanks

percent_tip = float(input(" Please Enter the percent of the tip:")("%"))

For example, before the user types anything they should see:

Please Enter the percent of the tip:

Once they begin typing the number 20 they should see:

Please Enter the percent of the tip: 20

After they hit <Enter> they should see:

Please Enter the percent of the tip: 20%
Answer

Please try this if this is what you are asking for:

import sys
import timepercent_tip = ""while percent_tip in "123456789": # This part checks with the "if" statement, if its not a integer then it returnspercent_tip = input("Please Enter the % of the tip: ")if percent_tip in "123456789":print(str(percent_tip) + " %") # Prints the number and the percentage symbolsys.exit() #stops the shellelse:time.sleep(.100) #Shell waits then goes back in the while loop (unless its controlled by the "while" and "if")

Please do not try to harden yourself with a code that you don't know how to do it.

https://en.xdnf.cn/q/118315.html

Related Q&A

Discord.py Self Bot using rewrite

Im trying to make a selfbot using discord.py rewrite. Im encountering issues when attempting to create a simple command. Id like my selfbot to respond with "oof" when ">>>test&q…

int to binary python

This question is probably very easy for most of you, but i cant find the answer so far.Im building a network packet generator that goes like this:class PacketHeader(Packet): fields = OrderedDict([(&quo…

Get aiohttp results as string

Im trying to get data from a website using async in python. As an example I used this code (under A Better Coroutine Example): https://www.blog.pythonlibrary.org/2016/07/26/python-3-an-intro-to-asyncio…

Waiting for a timer to terminate before continuing running the code

The following code updates the text of a button every second after the START button was pressed. The intended functionality is for the code to wait until the timer has stopped before continuing on with…

PySpark: how to resolve path of a resource file present inside the dependency zip file

I have a mapPartitions on an RDD and within each partition, a resource file has to be opened. This module that contains the method invoked by mapPartitions and the resource file is passed on to each ex…

Convert normal Python script to REST API

Here I have an excel to pdf conversion script. How can I modify it to act as a REST API? import os import comtypes.client SOURCE_DIR = D:/projects/python TARGET_DIR = D:/projects/python app = comtypes…

How to track changes in specific registry key or file with Python? [closed]

Closed. This question is seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. It does not meet Stack Overflow guidelines. It is not currently accepting …

How to use Android NDK to compile Numpy as .so?

Because the Numpy isnt a static library(it contains .py files, .pyc files, .so files, etc), so if I want to import it to my python code which is used in an Android phone(using CLE), I should recompile …

passing boolean function to if-condition in python

I"m learning python, and Im trying to do this, which I thought should be trivial, but apparently, its not. $python >>> def isTrue(data): ... "ping" in data ... >>>…

Unsupported operand type(s) for str and str. Python

Ive got the IF statement;if contactstring == "[Practice Address Not Available]" | contactstring == "[]":Im not sure what is going wrong(possibly the " "s?) but I keep ge…