Aggiungere un numero random in un file

Aggiungere un numero random in un file

In questa lezione svilupperemo un semplice algoritmo per aggiungere un numero random in un file in Python. Supponiamo di avere un file che contiene un numero. Innanzitutto stampiamo il numero contenuto nel file, dopo generiamo un numero random e lo sommiamo al numero che è contenuto nel file. Poi sommiamo i due numeri e aggiungiamo … Leggi tutto

Aggiungere contenuto a un file in Python

Aggiungere contenuto a un file in Python

In questa lezione studieremo come aggiungere contenuto a un file in Python già esistente, utilizzando la modalità append. Aggiungere contenuto a un file in Python – primo esempio In questo primo esempio utilizzeremo il nostro file rubrica.txt che già contiene dei dati ed aggiungere dei nuovi contatti. Ipotizziamo ad esempio che il file contenga questi … Leggi tutto

readline Python

readline Python

In questa lezione studieremo il metodo readline di Python necessario per la lettura di un file di testo. Questo metodo restituisce una riga di caratteri, incluso il carattere di fine riga, ovvero il carattere \n. readline Python – primo esempio Facciamo un primo esempio su un file rubrica che contiene i seguenti contatti di esempio: … Leggi tutto

JavaScript projects

Progetti JavaScript

In this article we will develop some simple JavaScript projects, such as displaying a counter that is incremented in various ways. JavaScript projects – counter In this first project we will build a counter using only Vanilla JavaScript. Try clicking on the buttons below to increase or decrease the counter variable which starts from the … Leggi tutto

JavaScript isNaN

isNaN JavaScript

JavaScript isNaN function determines whether the value passed as an argument is not a number. The syntax is therefore the following: isNaN(value). The function returns a Boolean value that is true if the argument passed is not a number, otherwise it returns false. JavaScript isNaN – examples In all the examples presented under the isNaN … Leggi tutto

Fibonacci JavaScript

Successione di Fibonacci in JavaScript

In this lesson we will implement a Fibonacci sequence algorithm in JavaScript. First of all, remember that the Fibonacci sequence is a sequence of positive integers in which each number, starting with the third, is the sum of the previous two and the first two are 1, 1. So, for example if I want to … Leggi tutto

slice in JavaScript

slice in JavaScript

Il metodo slice sulle stringhe in JavaScript consente di estrarre una parte di una sottostringa da una stringa. La sua sintassi è la seguente: string.slice(inizio, fine) Dove i due parametri inizio e fine sono opzionali. Il valore di inizio è un valore numerico che indica da dove deve partire la selezione, mentre il valore fine … Leggi tutto

Nesting for loops

JavaScript for cicli annidati

In this lesson we talk about nesting for loops in JavaScript, with the for loop. So we will see how to use a loop inside another loop. To explain the concept of nested loop let’s try to create a table using html and javascript. Nesting for loops – table So let’s suppose we want to … Leggi tutto

JavaScript toString

toString JavaScript

JavaScript toString method is used to convert an array to a string. The array to be converted can contain any data, such as numbers, objects, strings, etc. It is usually used to converter numbers in strings. The syntax of this method is very simple: array.toString(). The toString() method therefore returns a string. Since the original … Leggi tutto

Dati di input in un file di testo

Dati di input in un file di testo

In questa lezione andremo a memorizzare dei dati di input in file di testo in Python, creando una semplice rubrica che contiene i nomi ed i telefoni dei nostri amici. Primo esempio – dati di input in un file di testo Facciamo un primo esempio memorizzando un dato di input alla volta nel file rubrica.txt. … Leggi tutto

write Python

write Python

In questa lezione studieremo il metodo write in Python per poter scrivere sui file di testo. Dopo aver aperto il file in scrittura possiamo infatti scrivere su di esso. f = open(“coding.txt“, ‘w‘)f.write(“Il coding è fondamentale per incrementare il pensiero logico”)f.close() #chiusura stream In questo semplice esempio abbiamo creato un oggetto f sul quale abbiamo … Leggi tutto

open in Python

open in Python

In questa lezione studieremo la funzione open in Python, ovvero vedremo come aprire un file di testo o binario. Nella precedente lezione abbiamo parlato di file e abbiamo visto la differenza tra file binari e di testo (o ASCII). Nei nostri esempi saranno usati principalmente file di testo per memorizzare archivi sia con lunghezza fissa … Leggi tutto

JavaScript shift and unshift

Shift e Unshift in JavaScript

With the shift and unshift methods I remove and add respectively an element at the beginning of each array in JavaScript. The syntax of these methods is as follows: array.unshift (element1, element2,…, elementN) array.shift() As we can see with the unshift method it is possible to insert more than one element between round brackets, separated … Leggi tutto

JavaScript pop

Pop JavaScript

In this lesson we will cover the pop method in JavaScript, which is useful for deleting elements in an array. In the previous lesson we have dealt with the push method and we have seen how to add elements to our queued array, now we will see how to delete them. So to remove or … Leggi tutto

JavaScript array push

Push JavaScript

In this lesson we will see how to insert data into a JavaScript array push method, useful to insert element in array. The syntax of this method is as follows: array.push(element). Where array is the name of our array we want to populate. Element represents what we want to insert in the array. You can … Leggi tutto

JavaScript array

array javascript

In JavaScript an array is a useful tool for storing multiple data even of different types. In fact, JavaScript, like other programming languages, allows the creation and management of arrays. There are various ways to define an array in JavaScript, in this tutorial we will analyze them all and see which is more congenial. JavaScript … Leggi tutto

createTextNode JavaScript

createTextNode JavaScript

Continuiamo il nostro tutorial utilizzando il metodo createTextNode in JavaScript, ovvero il metodo che ci consente di inserire del testo in un nodo. Infatti, dopo aver creato un nuovo elemento oppure su un elemento già esistente, si può avere la necessità di inserire del testo al suo interno. Per fare ciò si può utilizzare ad … Leggi tutto

JavaScript createElement

dom in javascript

In this lesson we study JavaScript createElement method, useful to create new elements in the DOM. In the previous article we saw how to manipulate the DOM in JavaScript and studied methods for selecting elements on a page. You can consult the article at the following link: https://www.codingcreativo.it/en/javascript-dom/. JavaScript createElement – How to create elements … Leggi tutto