How to do the function for input list of stock in python
like [p(1), p(2), . . . , p(n)], for example [ 23,
53, 55, 42, 31, 40 ]
Hi Adam4u
I'm afraid that code in your second post makes no sense. As I see it there are two things you could be trying to do.
option 1: user enters a number, and the computer assigns it an index number automatically
option 2: user enters a number and an index and the computer assigns that number to that index.
Both are possible, of course. Which do you want? Or is there something else that you want?
Here's an ugly implementation of option 1: - p=[] #sets up p as a list
-
while True: #infinite loop for data input
-
i=input("Enter any number (0 to quit): ")
-
if i==0: break #if user enters nothing break out of infinite loop
-
p.append(i) #append i as the next item in the list
-
-
#Once we've broken out of the loop, print of the values you've entered:
-
print p
-
#or if you want to be a bit fancy
-
for n,i in enumerate(p):
-
print "index ", n, "value ", i, " which is equal to ", p[n]
-
5 1975 bvdet 2,851
Expert Mod 2GB
You will have to clarify your question. I don't understand what you are trying to do.
BV - Moderator
i'm trying to do a functio that consists two input as arrays or (pairs)
and here what i came up with -
def main():
-
i = [n]
-
i, n = input("Enter any number: ")
-
print " The first input is", i, " and the index is", n
On other hand, I want to print out the number of any integer entered with its array index between bracket... Thanks in advance
bvdet 2,851
Expert Mod 2GB
Does this help any? - >>> numbers = [0,1,2,3,4,5,6,7,8,9]
-
>>> for i, num in enumerate(numbers):
-
... print "The number is %s and the index is %s" % (num, i)
-
...
-
The number is 0 and the index is 0
-
The number is 1 and the index is 1
-
The number is 2 and the index is 2
-
The number is 3 and the index is 3
-
The number is 4 and the index is 4
-
The number is 5 and the index is 5
-
The number is 6 and the index is 6
-
The number is 7 and the index is 7
-
The number is 8 and the index is 8
-
The number is 9 and the index is 9
-
>>>
Hi Adam4u
I'm afraid that code in your second post makes no sense. As I see it there are two things you could be trying to do.
option 1: user enters a number, and the computer assigns it an index number automatically
option 2: user enters a number and an index and the computer assigns that number to that index.
Both are possible, of course. Which do you want? Or is there something else that you want?
Here's an ugly implementation of option 1: - p=[] #sets up p as a list
-
while True: #infinite loop for data input
-
i=input("Enter any number (0 to quit): ")
-
if i==0: break #if user enters nothing break out of infinite loop
-
p.append(i) #append i as the next item in the list
-
-
#Once we've broken out of the loop, print of the values you've entered:
-
print p
-
#or if you want to be a bit fancy
-
for n,i in enumerate(p):
-
print "index ", n, "value ", i, " which is equal to ", p[n]
-
bvdet and Glenton thanks for your help... i just figured it out from online search, Glenton you were closed to what i wanted.. but thanks
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jeffrey Silverman |
last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree
structure from that list.
Basically, I want to turn this:
$list = array(
array( 'id' => 'A', 'parent_id' => null, 'value'...
|
by: George M Jempty |
last post by:
Is there a good linked list implementation in the public domain? Or
that someone on this group has already written that they'd like to put
in the public domain, right here on this newsgroup? I've...
|
by: JustSomeGuy |
last post by:
I need to write an new class derived from the list class.
This class stores data in the list to the disk if an object
that is added to the list is over 1K in size.
What methods of the std stl...
|
by: Kieran Simkin |
last post by:
Hi all,
I'm having some trouble with a linked list function and was wondering if
anyone could shed any light on it. Basically I have a singly-linked list
which stores pid numbers of a process's...
|
by: JS |
last post by:
I have a file called test.c. There I create a pointer to a pcb struct:
struct pcb {
void *(*start_routine) (void *);
void *arg;
jmp_buf state;
int stack;
};
...
|
by: bitshadow |
last post by:
I've been working on a link list implementation and I'm driving myself
crazy trying to understand something.
assuming i have a list and i have the following quasi pseudocode:
add(list *head):...
|
by: Fazana |
last post by:
I was doing one of the question but my program was not working properly. Can anyone help me with it pliz........
Here is the question for the program
Question.
Part 1.
Add the function...
|
by: Lysander |
last post by:
I have not seen this feature documented before, so I thought I would share it with you, as I will be using it in a later article.
For a combo or list box, the source data is normally a...
|
by: =?Utf-8?B?Sm9lbCBNZXJr?= |
last post by:
I have created a custom class with both value type members and reference type
members. I then have another custom class which inherits from a generic list
of my first class. This custom listneeds...
|
by: Atos |
last post by:
SINGLE-LINKED LIST
Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |