python code to generate a Nigerian plate number [closed] - python-3.x

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I need a code designed with python to generate vehicle plate numbers
for platecode in range(100):
print('KJA'+'platecode'+'AA')
expected result is = KJA001AA till 100

The problem with your code is that you're not using the platecode variable, you're just putting it in as a string. 'platecode' (string) =/= platecode (variable). And as a comment stated, you want to zero-pad it. To do so use the format method:
for platecode in range(100):
print("KJA{0:03d}AA".format(platecode))
(Note that we use the platecode variable, not a string 'platecode'.)
To explain what the format method is doing: When format is called, it replaces braced sections ("{0:03d}") with the arguments to format (in this case, platecode). The first 0 says to access the argument at index 0; the colon indicates the beginning of the format specifier. The second zero says to zero-pad the number; the 3 says to use a minimum of 3 digits; and the d indicates to print in base 10, decimal.

Related

Understanding void functions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Write a program named program52.py that uses main and a void function named numbers that takes no arguments and does not return anything. The numbers function generates 5 random integers, each greater than 10 and less than 30 (duplicates are okay), and prints them all on one line separated by spaces. A loop is required for this, and the loop should also total up the integers so the sum can be displayed when the loop ends. The main function should call the numbers function.
This is the requirements for them, I'm very new and I've had a great deal of trouble using void functions so as you might imagine this has been difficult. I was wondering if anyone had insight on how to do this, I would not like the solution I want to understand how to do it properly.
In python, you don't need to define something to return for your function. It is by default void unless you add a return statement.
Refer to these for how to make functions:
https://www.w3schools.com/python/python_functions.asp, https://realpython.com/python-main-function/
Additionnal sources to help in your work:
https://www.w3schools.com/python/python_for_loops.asp,
https://www.techbeamers.com/python-random-number-tutorial/
You can quickly find answers to this type of question by looking it up on many websites like: W3Schools, GeeksForGeeks, RealPython and many others.

What does the prompt '...' in python 3 mean? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
As an exercise we need to explain what happens when we leave an open paranthesesis in a print statement.
Doing so does not give us an error nor a value, the resulting line gives us a prompt consisting of dots instead of arrows. Does this situation/prompt have a name and can someone explain?
for example:
>>>print('Hello'
...
The official name is secondary prompt. It is used when inputting incomplete constructs, for example not closing any set of parentheses or when defining a function.
The three greater-than signs (>>>) prompts for the next command, which the interpreter can process at once. The three dots (...), in its turn, prompts the continuation lines, such as print(: interpreter can't process your command at once, because it, in this case, doesn't know the arguments you want to pass to the function.

Seating arrangement problem in a circular table [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
N people sit around a circular table. You have to find the probability that two particular people won't be sitting together.
The input will have the number N and the output should have the probability printed as a float type number rounded off to four decimal places.
Here's the link for the derived formula
You can find the step by step derivation over there
Here's the simple python implementation as per the thread
n = 5
result = (n-3)/(n-1)
print(result)
n= int(input())
import math
print(round(1-math.factorial(n-2)*math.factorial(2)/math.factorial(n-1),4))

Python 3.3 Print('string', end='') [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Quick question, is there any difference between these two following bits of code?
Example 1
print("hello,", end='')
print(" world")
Example 2
print ("hello, world")
I don't see a difference in output, why would I use one over the other?
Thanks in advance for any answers
You would only really use the first one in cases where you may want to keep outputting things onto the same line (think logging something onto one line in a loop for some reason).
Otherwise use the simpler option.
If you use end='' it avoids the newline that python normally inserts in a print statement.
In practice, there's no reason to do it the first way with a short string like that, but if you wanted to put other variables in the output, it could be useful.

How to avoid scientific notation for large numbers in verilog? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In a case statement case(s), the nvalue of s is increased by the power of 2.
input[127:0] s
output[127:0] y
case(s)
128'b1: y=a1;
128'b2: y=a2;
...
When it goes to 2^64, the number is so big and it will be represented automatically by scientific notation, eg.
128'b1.84467e19: y=a64
This will give me a syntax error, is there a way to avoid this?
I don't want to define it as real, since I want to synthesise this code.
If only one bit of s is set (one-hot), you might be able to use "Constant expression in case statement" (see ยง12.5.2 of the free IEEE Std 1800-2012):
case (1'b1)
s[0] : y=a1;
s[1] : y=a2;
s[127]: y=a64;
endcase

Resources