投稿

1月, 2021の投稿を表示しています

What is list and set in Python?

Lists and tuples are standard Python data types that store values in a sequence. Sets are another standard Python data type that also store values. The major difference is that sets, unlike lists or tuples, cannot have multiple occurrences of the same element and store unordered values. What does set () do in Python? set() method is used to convert any of the iterable to sequence of iterable elements with distinct elements, commonly called Set. Parameters : Any iterable sequence like list, tuple or dictionary. Returns : An empty set if no element is passed. Non-repeating element iterable modified as passed as argument.

任意個の体重を入力し平均を計算する

イメージ
# calculate average weight wlist=[] for i in range(0,500): mes="Input your weight (0 exit): "+str(i)+" " w=input(mes) iw=int(w) if iw==0: break wlist.append(iw) print(wlist) print("input number = %d " % len(wlist)) print("sum = %d average = %d " %(sum(wlist) , sum(wlist)/len(wlist))) 補足:体重の値に0が入力されるまで、500人以下なら何人でも体重の値を受け付け、 その平均値を求めます。

Basic List Operations

>>> >>> len([1,2,3]) 3 >>> [1,2,3]+[4,5,6] [1, 2, 3, 4, 5, 6] >>> ["hello! "]*3 ['hello! ', 'hello! ', 'hello! '] >>> 3 in [1,2,3] True >>> max([1,2,3,4]) 4 >>> min([1,2,3]) 1 >>> list((1,2,3)) #converts a tuple into list [1, 2, 3] >>> for x in [10,20,30]: print(x) 10 20 30 >>>

What are sequence types in Python?

What is sequence a particular order in which related events, movements, or things follow each other. a set of related events, movements, or things that follow each other in a particular order. what are 6 built-in types of sequence in python In this Python Sequence Tutorial, we will discuss 6 types of Sequence: String, list, tuples, Byte sequences, byte array, and range object. What are sequence types in Python? There are seven sequence types: strings, Unicode strings, lists, tuples, bytearrays, buffers, and xrange objects. Dictionaries and sets are containers for sequential data. See the official python documentation on sequences: What are the sequence data types? Sequences allow you to store multiple values in an organized and efficient fashion. There are several sequence types: strings, Unicode strings, lists, tuples, bytearrays, and range objects. Dictionaries and sets are containers for non-sequential data. Enable Ginger Cannot connect to Ginger Check your in...

ブログ編集 作詞ビュー 絵文字挿入、配置、

 ああああああ いいいい うううう 11111 22222 3333 ああああ😚😑⇨⌚🌂 リンクここから

ブログ編集テスト HTLM ページ 斜体、太字、link,

イメージ
aaaaa bbbbb ccccc rrrr aaaa bbbb cccc

画像表プログラム(ファイルダイアログから画像ファイルを指定)

イメージ
import tkinter as tk import tkinter.filedialog as fd import PIL.Image import PIL.ImageTk def openFile(): fpath=fd.askopenfilename() if fpath: print(fpath) dispPhoto(fpath) def dispPhoto(path): newImage=PIL.Image.open(path).resize((300,300)) imageData=PIL.ImageTk.PhotoImage(newImage) imageLabel.configure(image=imageData) imageLabel.image=imageData root=tk.Tk() root.geometry("400x350") btn=tk.Button(text="ファイルを開く", command=openFile) imageLabel=tk.Label() btn.pack() imageLabel.pack() tk.mainloop()

再起関数 プリント

イメージ
#再起関数 def printNumber1(n): if n 実行結果

つるかめ算の自動回答プログラム

イメージ
''' 鶴と亀の頭の数の合計と足の数の合計から、 鶴と亀の数を調べます。 ''' def turukamezan(head,leg): print("head : %d , leg : %d " % (head, leg)) ans=0 for turu in range(0,head+1): for kame in range(0,head+1): if turu+kame == head and (turu*2+kame*4 == leg): print("turu : %d , kame : %d " % ( turu , kame)) ans=1 break if ans == 0: print("no answer") turukamezan(3,10) turukamezan(9,26) turukamezan(9,25) turukamezan(4,10)

tkinter 数当てゲーム 改良 トライカウント表示

イメージ
import tkinter as tk from random import randint def get(): global count_number number = guess.get() if number random_number: count_number +=1 count.set(count_number) hint.set("Lower!") root.after(1000, clear_hint) else: hint.set("Well guessed!") count_number +=1 count.set(count_number) root.after(5000, setup) def setup(): global random_number global count_number random_number = randint(1, 100) guess.set(0) count.set(0) hint.set("Start Guessing!") root.after(5000, clear_hint) def clear_hint(): hint.set("") root = tk.Tk() root.geometry("300x60") root.title("数当てゲーム(1-100)") hint = tk.StringVar() guess = tk.IntVar() count=tk.IntVar() random_number = 0 count_number=0 tk.Entry(textvariable=guess).grid(column=0, row=0) tk.Button(root, text="Guess", command=get).grid(column=1, row=0) tk.Label(root, tex...

tkinter 数当てゲーム

イメージ
from random import randint def get(): number = guess.get() if number random_number: hint.set("Lower!") root.after(1000, clear_hint) else: hint.set("Well guessed!") root.after(5000, setup) def setup(): global random_number random_number = randint(1, 100) guess.set(0) hint.set("Start Guessing!") root.after(5000, clear_hint) def clear_hint(): hint.set("") root = tk.Tk() root.geometry("300x200") root.title("数当てゲーム(1-100)") hint = tk.StringVar() guess = tk.IntVar() random_number = 0 tk.Entry(textvariable=guess).grid(column=0, row=0) tk.Button(root, text="Guess", command=get).grid(column=1, row=0) tk.Label(root, textvariable=hint).grid(column=0, row=1) setup()

random.randint

random.randint(a, b)¶ Return a random integer N such that a

C言語と異なる点

① 変数の宣言不要です ② char 型はない。 すべて文字列で表す。 ③ 一つの変数で、異なる型を扱える。 最後に代入した型となる。 ④ OOPである。 ⑤ プログラム構造をインデントで表現する ⑥ 配列はなく、文字列、リスト、タプル などで操作する。 ⑦ コンパイラーではなく、インタープリターである。 ⑧ 高速処理が必須の場合は、関数を用いて書く(関数自体はC言語で作られている。) ⑨ 構造体はクラスで書く ⑩ ポインター はない。 ⑪ 自前関数の定義は参照前に定義する。 ⑫ 参照するモジュールは、プログラムの先頭でimportする

Add image on a Tkinter button

イメージ
 プログラムソース from tkinter import * from tkinter.ttk import * root = Tk() Label(root, text='GeekforGeeks',       font=('Verdana',15)).pack(side=TOP,pady=10) photo = PhotoImage(file=r"c:\python\mydog2020.PNG") photoimage=photo.subsample(3,3) Button(root,text='Click Me !',        image=photoimage,compound=TOP).pack(side=TOP) mainloop() compound=LEFT に変更した場合 Tkinter  is a Python module which is used to create GUI (Graphical User Interface) applications with the help of varieties of widgets and functions. Like any other GUI module it also supports images i.e you can use images in the application to make it more attractive. Image can be added with the help of  PhotoImage()  method. This is a Tkinter method which means you don’t have to import any other module in order to use it. Important:  If both image and text are given on  Button , the text will be dominated and only image will appear on the Button. But if you want to show both...

WEB SITE: mumpy.org/learn

イメージ
mumpy.org/learn

matplotlib.pyplot.plot

matplotlib.pyplot.plot