# How to multiply a list by an integer?

This is so basic I'm embarrassed to even ask the question, but I've tried all the possibilities I can think of, and searched two SM guides (SM Tutorial and SM for Undergrads), and I can't find out how to do this. I want to multiply a list of rational numbers (fractions) by an integer. I've tried with lists and sets (although sets wouldn't really work, because the list of fractions contains repetitions), and I've tried with the single integer as simply a number and as a list. But I always get an error message, saying "unsupported operand type(s)" or something similar. Here is an example of what I'm trying to do:

a = [1, 1/2, 1/3, 3/8, 1/5, 1/3, 3/14, 1/4, 1/6, 1/4,]

b = 840

print (a ^ b)

Help for a clueless newbie would be greatly appreciated. (Also, if anyone can recommend a tutorial or guide that will explain how to do these sorts of things in SM, that would be even better!)

edit retag close merge delete

Sort by » oldest newest most voted

like this

sage: a = [1, 1/2, 1/3, 3/8, 1/5, 1/3, 3/14, 1/4, 1/6, 1/4]
sage: b = 840
sage: b * vector(a)
(840, 420, 280, 315, 168, 280, 180, 210, 140, 210)
sage: [b * n for n in a]
[840, 420, 280, 315, 168, 280, 180, 210, 140, 210]

more

Thank you! Do you know of a site where I can learn why this works, and how similar problems have to be programmed to work?

( 2021-07-13 21:47:56 +0200 )edit

You may want to learn Python first. There are many books abut Python.

( 2021-07-14 08:19:33 +0200 )edit

thank you.

( 2021-07-14 17:36:14 +0200 )edit

## Stats

Seen: 382 times

Last updated: Jul 13 '21